Posts by Wallace Maxters • 102,340 points
1,984 posts
-
27
votes4
answers1065
viewsQ: Is there any way to extend an object in javascript?
In PHP, we can usually extend a class using the keyword extends which points to the class that will have inherited methods and attributes. Example: class MyObject extends ArrayObject { } And if I…
-
3
votes6
answers498
viewsQ: What is the safe way to define a default value for a function parameter?
In PHP, I can make a function have by default a value in a parameter. Example: function func($a = 1, $b = 2) { return $a + $b; } What about Javascript? I can make the same statement on Firefox 39;…
-
7
votes2
answers260
viewsQ: Is there any difference between an infinite loop with for and while?
In PHP, it is possible to generate a loop infinity with while simply passing the parameter true. Example: while (true) { echo "Ao infinito e além"; } It is also possible to generate this through…
-
0
votes2
answers1310
viewsA: How to know what is the class name of a javascript object?
There is also this little form: var f = new FormData; Object.prototype.toString.call(f) // [object FormData] With the idea of @felipsmartins, this can be done: function get_class(obj) { return…
javascriptanswered Wallace Maxters 102,340 -
2
votes2
answers1310
viewsQ: How to know what is the class name of a javascript object?
In PHP we can find out which instance an object is coming from through the function get_class. Thus: $ao = new ArrayObject; get_class($ao); // ArrayObject What about javascript? How can we do this?…
javascriptasked Wallace Maxters 102,340 -
3
votes4
answers31971
viewsA: Can I write Javascript in PHP?
You can yes. The problem is that this makes it a little difficult to read your code (in javascript), since it is a PHP string, and hardly your text editor will signal that the syntax is correct or…
-
5
votes4
answers989
viewsA: Read input value type file doubt
When you do that $("input[type='file']")[0], you are accessing the object HTMLInputElement, which is native to javascript. In this element, there is the property files. Example:…
-
2
votes2
answers1317
viewsA: Why content-type false AJAX - JQUERY
When you use the contentType with the value false, you are forcing jQuery not to pass the default value to the contentType request. The default, as quoted above, is…
-
2
votes1
answer748
viewsQ: How can I abbreviate a name to 2 words, ignoring (from, da, dos, das)?
I have a user table on the system where the full user name is registered. But, when displaying these names in the system, I should only use two words of that person’s name to display. And when the…
-
4
votes2
answers357
viewsQ: Portable blade and performance
In the Laravel, we usually use the Blade in order to write a view. Example: @unless($variable) <p>Nenhum dado encontrado</p> @else @foreach($variable as $v) <p>{{ $v }} </p>…
-
2
votes6
answers10518
viewsA: Difference between php <?php tags and <?=
Just to complement with information, one of the above-mentioned forms is called by PHP alternative syntax, or alternative syntax. It serves to simplify the were of writing a control or repeat…
phpanswered Wallace Maxters 102,340 -
3
votes6
answers8335
viewsA: How to know if the form is sent
The simplest way to know if a post was sent is through REQUEST_METHOD. Try to do something like: if ($_SERVER['REQUEST_METHOD'] == 'POST') { } REQUEST_METHOD indicates the method used in the…
phpanswered Wallace Maxters 102,340 -
2
votes2
answers197
viewsA: Block splitting mysql results
I do not know if for your case this would be advantageous because of performance, but what could be done is to divide the result through function array_chunk. For that we would have to use…
phpanswered Wallace Maxters 102,340 -
2
votes3
answers466
viewsA: How to detect if an element is accompanied by text with jQuery?
As @Dontvotemedown said, "... this is a good exercise". $(".box").filter(function(i) { var $that = $(this); var node = $that.contents().get(0); if ($that.contents().length == 1 &&…
jqueryanswered Wallace Maxters 102,340 -
4
votes3
answers466
viewsQ: How to detect if an element is accompanied by text with jQuery?
I have a certain div.box that will be repeated several times, and some of them have a link (a.link) with a specific class. Example: <div class="box" data-id="1"> Primeiro texto </div>…
jqueryasked Wallace Maxters 102,340 -
3
votes4
answers599
viewsA: Is there a problem omitting the semicolon in a php tag with only one expression
In cases like expressions using the altering syntax, I do not use the ;. Example: <?php foreach($array as $value) : ?> <?php endforeach ?> Some programmer friends criticized the lack of…
phpanswered Wallace Maxters 102,340 -
2
votes1
answer710
viewsA: UTF-8 Charset error when returning from database
Set the desired charset at runtime. If you are using PDO, do: $pdo->exec('SET NAMES utf8'); In Mysqli: mysqli_query($mysql, 'SET NAMES utf8')…
-
3
votes2
answers109
viewsA: problems deleting file from unlink()
Correct @rray response. The problem is in relation to end accept only variables, not array expressions. Therefore, this function accepts an argument that is a variable, because it is a parameter…
-
4
votes2
answers641
viewsA: Doubts with relationships in Eloquent
You can use the method with to load relationships. When you convert to JSON, this is the best way to load the related data. There are two ways:…
-
4
votes2
answers1004
viewsQ: How to put » and « in :before?
I need to put one » » and a « « in the attribute :before of a given, element. How do I do this in CSS? ul.breadcumb > li:after{ content: '»'; /** Isso aqui não funciona…
-
5
votes4
answers3187
viewsA: Should one use break in going?
Perhaps this depends on language. But this would be more a matter of good practice recommended by your teacher, than having "a right" and "a wrong". I say this because there are people who use…
-
9
votes1
answer823
viewsQ: What is the Null Object standard for?
I asked that question What is the purpose of Emptyiterator? at SOEN, because I found no answers here. Then I was told in a response from the SOEN of a pattern called Null Object. What is the purpose…
-
0
votes1
answer60
viewsA: What is jQuery’s Event.namespace for
A event.namespace can be useful for controlling which specific events I want to remove. Example: Suppose I have three events of scroll linked to window. I want to remove one of them specifically,…
jqueryanswered Wallace Maxters 102,340 -
1
votes1
answer60
viewsQ: What is jQuery’s Event.namespace for
In the jQuery documentation, there is the explanation of event.namespace. This allows you to use an event (or create an event) specific to jQuery, with a namespace, through a . point and a name in…
jqueryasked Wallace Maxters 102,340 -
2
votes2
answers987
viewsA: How do I count the number of files in a folder with PHP?
The most appropriate way in my view would be to use the class FileSystemIterator, which is part of the standard class set offered by PHP. $iterator = new FilesystemIterator(__DIR__,…
-
1
votes2
answers987
viewsQ: How do I count the number of files in a folder with PHP?
In PHP, what is the fastest and most efficient way to read the amount of files present in a given directory. For example, I want the demo below to return 3. pasta/ index.php dev.php .htaccess…
-
2
votes3
answers744
viewsA: Split array and sort
In the most elegant way possible, let’s go to the solution: Your array is as follows: $dados = array( 'Ato001_1981', 'Ato002_1980', 'Ato003_1982', 'Ato003_1983', 'Ato004_1982', 'Ato013_1981',…
-
10
votes3
answers632
viewsQ: Can apache rewrite to external url?
I have an application running on local. At the same time I have the application that is already running in production - namely a social network. I have photos of many users in this system that is in…
-
6
votes2
answers558
viewsQ: What is the undescore "_" in the MYSQL LIKE?
In a previous question regarding LIKE in the MYSQL, I should avoid the injection of "%" in a query where I use "LIKE"?, a question has arisen regarding the _ (undescore) can be used on the operator…
-
2
votes3
answers2496
viewsA: How to submit a form automatically and without refresh?
The simplest way to do that would be with change of jQuery. $('[name=valor]').change(function () { $('[name=valor_analog]').submit(); }); Another way to do it is by using the addEventListener, if…
-
3
votes1
answer130
viewsQ: Should I avoid injecting "%" in a query where I use "LIKE"?
I have a page where I consult the user through the name. The query aims at the use of LIKE to capture the user name from the first letter onwards. So I consult this way SELECT * FROM usuarios WHERE…
-
3
votes1
answer431
viewsQ: Why does ORDER BY RAND() slow down the query? Is there another alternative?
I had just asked questions regarding the ordering of random values through the MYSQL. From there I began to notice an uncomfortable slowness in the suggested system of friendships here of the…
-
9
votes5
answers34006
viewsA: How to return the last record of an array with Javascript or jQuery?
Another way to get the last element of array, whereas it does not remove the last element of the array, would be using the function slice pointing to the last element through the -1. a = [1, 2, 3]…
-
4
votes1
answer344
viewsA: Is there any way to define a random order by an established order?
I ended up discovering that it is some very simple. It follows the same reasoning of the question How to sort the data of a query by predefined values?. An important issue is that the ORDER BY, when…
-
0
votes1
answer344
viewsQ: Is there any way to define a random order by an established order?
If the title of my question was confused, I explain: I want to sort a result of a certain query of MYSQL. Example: SELECT * FROM usuarios ORDER BY cidade = 'BH' DESC, cargo = 'Programador' DESC…
-
0
votes3
answers273
viewsA: What can change with the variadic Function implementation?
Just as a complement to the previous answers: a simple example is to improve the syntax and decrease the function call, improving the performance. Formerly:…
-
5
votes2
answers204
viewsQ: What is the name of the ... operator used in PHP 5.6?
From the PHP 5.6 we now have the possibility to invoke or declare a function, stating that the arguments are infinite, through the .... Example: function add(... $arguments) { return…
-
20
votes5
answers2497
viewsQ: What is the purpose of the "Spaceship Operator" <=> of PHP7?
I was just taking a look at the New Features of PHP 7 and I came across an operator, who I had never seen in any programming language. The PHP Handbook demonized him of Spaceship Operator. I’ll…
-
2
votes1
answer103
viewsQ: Self invoking functions in PHP 7. What are the advantages?
I know that in the javascript the use of self invoking functions, especially when it comes to variable scope protection. I was doing tests on PHP 7 and I see that we have the same possibility to use…
-
6
votes3
answers887
viewsA: How to print a constant in the middle of a string, without concatenating?
A possible way would also be with something half-mad magic that php allows: We can declare the function value constant - that serves to get the value of the constant - and save it in the variable.…
-
11
votes3
answers887
viewsQ: How to print a constant in the middle of a string, without concatenating?
Is there any way to print a constant in the middle of a string, without using concatenation, as with PHP variables? Example: $nome = 'wallace'; echo "Meu nome é {$nome}"; In the case of constants, I…
-
8
votes4
answers1166
viewsQ: How to sort the data of a query by predefined values?
Using as an example, I have a certain user table, where that user’s city is, is a reference to another table. I need to order these users in a query according to the location of the current logged…
-
5
votes2
answers263
viewsQ: In a MVC structure, can we create a model that represents a View (SQL)?
I was arguing with a friend of mine about using views (I mean Mysql, not Mysql Pattern MVC). Hence a doubt arose in the following sense: A Model is used to represent a data structure, and you can…
-
0
votes6
answers896
viewsA: Rewrite and close array of a file
I’d do it this way. Suppose I have the following code: return array( 'nome' => 'Wallace', 'idade' => '25 anos' ); We could take the value of this file and save it in the same script. For this…
phpanswered Wallace Maxters 102,340 -
2
votes1
answer81
viewsQ: Is there a built-in server in php?
Sometimes we want to run a simple PHP script to perform tests, but we don’t want to spend time installing wamp, xampp or even installing the apache2 followed by PHP. Is there any way to run the…
-
5
votes1
answer81
viewsA: Is there a built-in server in php?
Yes, there is a way. From the version 5.4 PHP offers, in its own language, a built-in server. Just run the following code on the command line: php -S localhost:9000 This will cause PHP to create a…
-
1
votes2
answers1817
viewsQ: Is there any way to write code for the web without a python framework?
I find python a very interesting language. And as I develop for web, I would like to use it for this purpose. I know there are good frameworks like Flask and Django. But if I wanted to write small…
-
2
votes2
answers126
viewsA: Syntax error when trying to access static method on object saved in property!
In fact, the solution to this problem is simpler than it seems. Contrary to what is imagined, static methods are not only accessible by means of the "double two-point" ::. When it comes to…
-
2
votes2
answers239
viewsA: How to place a property name on a Javascript object?
I am seeing that you are trying to assign an attribute to the array as if it were an object by your example. [prop_name:{ [...] Perhaps something that can help you, since you are having…
-
10
votes2
answers1121
viewsQ: PHP7 anonymous class. What are the advantages?
According to the Manual for PHP, from the version PHP 7 it will be possible to define anonymous classes. Example: class SomeClass {} interface SomeInterface {} trait SomeTrait {} // Instanciamos a…