Posts by Wallace Maxters • 102,340 points
1,984 posts
-
12
votes3
answers1771
viewsQ: What is the purpose of the magical __clone method?
In PHP we have the magic method __clone. It serves to define a behavior when you clone an object through the keyword clone. So far so good. But I did not understand very well why to have this…
-
1
votes2
answers1924
viewsA: Disable the CSRF token of the Standard 5.2
You’re getting it wrong. The exception MethodNotAllowedHttpException is fired when you try to access a route POST via method GET (or any other method, I’m just exemplifying). The exception that is…
-
12
votes3
answers5760
viewsQ: Is there any equivalent of "$(Document). ready()" with pure Javascript?
In jQuery, we need to use $(document).ready() to know if the document has been loaded and then safely run our jQuery script. According to jQuery documentation A page can’t be manipulated Safely…
javascriptasked Wallace Maxters 102,340 -
4
votes4
answers1965
viewsQ: How can I detect the visibility of an element (without jQuery)?
How can I know if a particular element is not visible with pure Javascript? I know how to do it with jQuery, that’s how: $('.btn').click(function () { $('#box').is(':visible') ? $('#box').hide() :…
javascriptasked Wallace Maxters 102,340 -
2
votes2
answers69
viewsA: Differences between namespace syntax
There’s no difference between them. In PHP you accept namespace declaration with keys and no keys. In the case of the use of the keys, everything that is placed there will be part of the namespace…
-
4
votes1
answer2233
viewsA: Count element values from a PHP array
It’s very simple. Use array_map to list all elements with name TIPO. Then use the function array_count_values to know the result. $tipos = array_map(function ($value) { return $value['TIPO'];},…
-
3
votes4
answers1025
viewsA: How to make a LOOP run according to the return of a Promise (promise)?
You can work with recursion. You use an anonymous named function to reference itself and, if it is within the conditions, you run it again. The set condition avoids infinite recursion. var exemplo =…
-
5
votes2
answers9382
viewsQ: In CSS, is there any way to define the inline Hover?
I often need to develop templates for sending emails. But in some cases use the tag style to make style settings does not work. Thus, it is necessary to define the style values for inline elements.…
-
3
votes2
answers1225
viewsA: Catch anchor url with PHP
This is not possible. As this value is never sent to the served, it will not be available at $_SERVER['REQUEST_URI'] or similar predefined variables. You would need some kind of "magic" on the…
-
2
votes3
answers1509
viewsA: How do I resolve this conflict in php?
Have you tried this to set the default PHP encoding? ini_set('default_charset', 'UTF-8')
-
1
votes4
answers2195
viewsA: Fetch date 7 days before current php date
Still, it is possible to use the DateInterval in an easier way, if you are not getting used to the parameters of its instantiation, like me. Just use the method DateTime::createFromDateString();…
phpanswered Wallace Maxters 102,340 -
6
votes1
answer566
viewsA: How to assign 60 more days in a date compared to today’s PHP date?
You can pass a second argument to date to specify the date, through a timestamp. In this case, we will use strtotime to facilitate the service (this function creates a string-based timestamp that…
phpanswered Wallace Maxters 102,340 -
6
votes2
answers494
viewsA: How to make a daemon for the "mongod" command
If you are using Linux, you can do the following: nohub mongod & Nohup will keep the process running in the background, even if you drop the server (if you are using SSH). There is also a…
mongodbanswered Wallace Maxters 102,340 -
1
votes1
answer166
viewsQ: How to escape a key/braces on Blade?
In Blade, the key (or key) characters are intended to add the purpose of printing the content. It is complicated to a echo. But I was wondering if I really needed to display a piece of content,…
-
6
votes4
answers281
viewsQ: Is there a C# feature similar to PHP __call?
I have a lot of experience with PHP and, as I’m starting now with C#, it will be common for me to want to compare one language with another to find out if I can do something similar. In PHP, I can…
-
4
votes2
answers4348
viewsA: SSL error with file_get_contents
I thank my friend @Guilhermenascimento for his reply and @Bacco for helping in the chat to solve the problem. I finally managed to solve! Let’s take the necessary steps. I am using version 5.6 of…
-
15
votes2
answers5043
viewsQ: What is the meaning of a "Manifest" file in programming?
I believe I’ve seen a file called manifest related to some libraries of certain programming languages. If I remember correctly, there is a manifest in Android Studio. I also remember seeing a file…
terminologyasked Wallace Maxters 102,340 -
2
votes2
answers4348
viewsQ: SSL error with file_get_contents
When I try to open a url through file_get_contents, I’m having trouble when the page is https. I’m not talking about external pages, but in some libraries where the application’s own images are…
-
4
votes1
answer290
viewsQ: Which regular expression would be more appropriate to validate a Cronjob expression?
I’m looking to learn a little bit more about regular expressions. I thought of a good exercise that will be validating whether a cronjob expression is correct or not. Therefore, the possible…
regexasked Wallace Maxters 102,340 -
2
votes1
answer1596
viewsQ: What is the maximum of decimal places allowed in the PHP float?
I was using Psysh to test with numbers like float. I noticed that, after a certain amount, it begins to limit the decimal places. Example: $float = 1.1234567891011121314 echo $float; //…
-
9
votes7
answers10590
viewsA: How do I know if today’s date is Saturday or Sunday (weekend) in PHP?
I’ll give my pinch on my own answer: in_array(date('w'), [0, 6]) In the case, w returns the day of the week in numerical format, where 0 it is Sunday and 6, saturday. in_array will do the job of…
-
33
votes7
answers10590
viewsQ: How do I know if today’s date is Saturday or Sunday (weekend) in PHP?
I want to know the simplest possible way to find out if today’s date is Saturday or Sunday in PHP. What are the possible ways to do this?
-
2
votes3
answers3257
viewsA: Problem with Laravel date
Another option is to use the `Carbon Carbon library, created by Brian Nesbitt. She comes installed by default in Laravel. She is a class improvement DateTime quoted above.…
-
2
votes1
answer905
viewsA: Return name by id in view. PHP and Codeigniter
I believe the solution is to make a JOIN: $this->db->select('*'); $this->db->from('demandas'); $this->db->join('outra_tabela', 'outra_tabela.campo_chave = demandas.id'); $result =…
-
4
votes3
answers714
viewsA: Is filter_var() sufficient to avoid SQL Injection?
No. The filter_var is intended to validate and filter fields. Its main goal is not to prevent specific SQL Injection attacks, but only to sanitize data. Of course, for some cases it can actually be…
-
5
votes4
answers1988
viewsQ: Is there any way to know if I’ve done git push?
Whenever I need to update the repositories, I use the command git push. The problem is that sometimes I don’t know if I’ve pulled or not, by doing several things at the same time. Then to find out…
gitasked Wallace Maxters 102,340 -
5
votes2
answers2630
viewsA: See total records in Laravel
Make another select. It’s the simplest solution in this case. $counts = User::select(\DB::raw('count(*) as status_count, status')) ->groupBy('status') ->get(); $total_counts = User::count();…
-
8
votes1
answer159
viewsQ: How does logic work to figure out the size of the image?
In PHP and other programming languages, it is possible, through some special functions, to discover the image size. For example: list($width, $height) = getimagesize('images/icon.png'); I was…
-
4
votes1
answer54
viewsQ: Transactions does not work in structure creations/modifications?
I was looking on the internet if there was any way to run Transactions for operations of the type ALTER TABLE or CREATE TABLE in the Mysql. This is because in one of our systems, we used Migrations…
-
1
votes1
answer86
viewsQ: Is there any way to get the original value of an attribute of a Model then modify it?
I am using the Laravel 5 and would like to know if, after modifying an attribute of a model, it is possible to recover it. For example: $usuario = Usuario::where(['nome' =>…
-
2
votes3
answers563
viewsA: What does <!-- //--> mean in html / javascript?
That’s an HTML code comment. As far as I know this was used in the past, to make browsers that did not have Javascript support not have problems with this "new tag" <script>.…
-
2
votes2
answers176
viewsQ: What is the Box<T> declaration for?
I was taking a look at documentation of the Hack. I know that this language is a modification of PHP to introduce type checking. I saw that they put this example to demonstrate the use of classes, I…
-
6
votes1
answer1015
viewsA: Create zip archive of a folder
According to the reply of SOEN $zipFile = "./testZip.zip"; $zipArchive = new ZipArchive(); if (!$zipArchive->open($zipFile, ZIPARCHIVE::OVERWRITE)) die("Failed to create archive\n");…
phpanswered Wallace Maxters 102,340 -
3
votes1
answer1377
viewsA: How to implement a Route System in MVC?
I usually do it this way: Collection - The collection that will store all routes. Route - The class that represents a route. You must provide information like the Uri you want to capture and http…
-
13
votes1
answer292
viewsQ: What is the difference between "using" and "using Static"?
In a question I asked about C#, @Maniero answered me and put an example code in Dotnetfiddle. The code is this: using static System.Console; public class Program { public static void Main() { var…
-
1
votes2
answers471
viewsQ: How to get the difference between dates and turn into hours?
In MYSQL, I know I can return a difference between dates through the function DATE_DIFF. example: SELECT * FROM table WHERE DATEDIFF(NOW(), created) <= ? However, I need that in this DATEDIFF the…
mysqlasked Wallace Maxters 102,340 -
11
votes1
answer578
viewsQ: Why does iteration of a list with an anonymous object work with an array but not with List<Object>?
I tried the following iteration with C#: var objects = List<Object>{ new {Id = 2, Nome = "Wallace"}, new {Id = 4, Nome = "Cigano"} }; foreach (var user in objects) { Console.WriteLine ("Meu id…
-
6
votes1
answer480
viewsQ: In a C#console program, where is the main class set?
I’m doing my first console program in C#, just to do some tests. I have two classes: HelloConsole.MainClass and HelloConsole.Calc. I have the following code: using System; // Aprendendo o alias de…
-
2
votes2
answers90
viewsQ: In C# is there variadic Arguments (infinite arguments)?
In languages such as PHP 5.6 and Python, it is possible to define "infinite arguments", (in PHP it is called variadic args) in a function/method. For example, it is possible to define a function…
-
7
votes4
answers492
viewsQ: In C# is it possible to use a local alias for class or namespace?
In languages like Python or PHP it is possible to use a local alias for classes or namespaces. PHP example: use Vendor\Package\ClassName as C; use Vendor\Package as P; $class = new C; $class = new…
-
1
votes2
answers1269
viewsA: How can I treat Violation Constraint exception to show the user in a user friendly way
You can probably use a try/catch to capture a specific exception. try { Model::operations()->save(); } catch (\PDOException $e) { return redirect()->back()->withErrors('message', 'Erro ao…
-
14
votes2
answers19928
viewsA: Difference between file_get_contents and Curl ?
First of all file_get_contents is intended to read the contents of a file. But can also be used to read urls. In PHP, there are some Wrappers (a definition similar to the http request protocol),…
-
2
votes1
answer84
viewsQ: Why does PHP allow you to "declare" $this with Extract?
I was doing some tests (playing) with the function extract and compact PHP. I was seeing how these two functions behaved with the variable $this. Then I performed the following tests: I tried to get…
-
2
votes3
answers4110
viewsA: How to get the first item of an object in javascript?
Underscorejs If you have the habit of using Undescorejs, it is possible to do so: var primeiro = _.first(_.toArray(objeto)); First we convert the Object for Array and then we took the first item…
javascriptanswered Wallace Maxters 102,340 -
4
votes3
answers4110
viewsQ: How to get the first item of an object in javascript?
I have the following object in javascript: { "tipo_entrega_id" : ["Valor não é válido"], "outro_campo" : ["valor deve ser preenchido"] } The values are not defining by me, they come dynamically…
javascriptasked Wallace Maxters 102,340 -
1
votes3
answers109
viewsA: How to display the excerpt from the script where the exception was released in PHP
I liked the reply of @Guilhermenascimento, but I would also like to leave a solution. In PHP, to do this, we could use the combination of SplFileObject with LimitIterator. The LimitIterator iterate…
-
4
votes2
answers564
viewsA: Is there a difference in using constants or variables in Classes?
His name says it all. Constants cannot be changed. Variables, as the name says, can be changed. So, briefly, use constants when you need an immutable value or important information. And the…
-
10
votes2
answers551
viewsQ: What is the point of an explicit C#interface implementation?
I usually use interfaces in PHP and I was able to do a similar example, only for tests, in C#. class MyClass : IWriter { public string Writer(string str) { return str; } } interface IWriter{ public…
-
12
votes1
answer208
viewsQ: Is there any error suppression mechanism in C# similar to the PHP arroba?
I’m studying C#, but I’m used to programming in PHP. I know that in PHP it is possible to delete some error messages by putting the @ (arroba) at the beginning of the expression. For example, if I…
-
2
votes1
answer5102
viewsQ: How to list the symlinks of a folder on Linux?
I’m using a tool to deploy in PHP. When I use the command, some symbolic links are created for certain folders. As I will run this command on a Linux server, I wonder if there is a command to list…