Posts by Wallace Maxters • 102,340 points
1,984 posts
-
0
votes0
answers129
viewsQ: Error in Ziparchive::close() call
When I’m using the method close to close the instance of ZipArchive I’m getting the following error: Ziparchive::close(): Read error: Is a directory The code of my application where the close is…
-
3
votes1
answer398
viewsQ: How to define a favicon? Is it mandatory to define it?
There are certain things that, by not doing constantly, I always end up forgetting how to do it. And one of them is the definition of a favicon for my website. What is the tag and attributes that I…
-
1
votes2
answers493
viewsA: Specify columns in a relationship with Laravel
In addition to the reply from @Diegosouza, it is possible to do this through the with using the relationship name as chave and the Closure as a value. Behold: $with['role'] = function ($query) {…
-
1
votes2
answers493
viewsQ: Specify columns in a relationship with Laravel
I have a relationship of User with Role. User::with('role')->get() In the case, User has the columns: id, name, role_id, created_at and updated_at. And Role has: id, name, slug, created_at,…
-
1
votes1
answer63
viewsQ: How to make an array index not required in a validation with Respect Validation Key?
I’m using the Respect\Validation to validate some fields in my form. I am using the method Validator::key() to be able to validate each value in an index of array that is sent from this form. I have…
phpasked Wallace Maxters 102,340 -
3
votes1
answer1213
viewsQ: Formdata is setting the string "null" to null values
I’m using a library called ngUpload. In it we have the option to send the data along with the upload of a particular file. I’m uploading this as follows: Upload.upload({ url:…
javascriptasked Wallace Maxters 102,340 -
2
votes2
answers483
viewsQ: Why was password_hash’s "salt" option discontinued in PHP 7?
I am getting the error while trying to do the following test: [ "salt" => "um salt grandão de responsa", "cost" => 12, ] password_hash (123456, PASSWORD_DEFAULT, $options); Is returning: Use…
-
4
votes3
answers10819
viewsQ: Conditional phone mask (with 8 or 9 digits) in Ui Mask. How to do?
I’m using the ui.mask to make the masks of inputs. I have a form whose field can receive both a value from a phone and a mobile phone. I have one currently a input similar to this: <input…
-
14
votes4
answers994
viewsQ: Why does Input Type Email validation accept pointless domains?
The input type[email] is intended to validate whether the field is being filled with a valid email. But several times I have gone through questioning in some projects about why this field accept…
-
7
votes2
answers1130
viewsQ: What is the safest way to identify that the upload file is an image?
I’m making a system where I can receive an image upload. To check on the server if the file type is image, I thought of this code: if (strpos($upload->getClientMimeType(), 'image') !== 0) { throw…
-
11
votes2
answers239
viewsQ: What could justify the jump of a number in a versioning system?
I realized that the long-dreamed PHP 6 has been canceled. Then, mysteriously, from version 5 jumped directly to version 7. I then had a doubt about the development of libraries and their respective…
versioningasked Wallace Maxters 102,340 -
2
votes1
answer251
viewsQ: Functions that are nicknames (aliases) should be used or not?
I remember that a while ago, when I was starting programming with PHP, I saw in some tutorials a recommendation, warning that it was to avoid using some functions that are nicknamed for others. I…
-
5
votes2
answers1791
viewsA: How do I detect if PHP is running on a command line or server?
You can do this by checking the value of the constant PHP_SAPI. If it is "cli", is running on the command line. Example: if (PHP_SAPI === 'cli') { // Está na linha de comando } else { // Está…
phpanswered Wallace Maxters 102,340 -
3
votes2
answers1791
viewsQ: How do I detect if PHP is running on a command line or server?
Sometimes, when I run a PHP script, I need to know if it is running on the command line or not, because if it is running on the command line, I can perform a different action. Is there any way to…
phpasked Wallace Maxters 102,340 -
2
votes1
answer235
viewsA: When password or login is wrong session is not closed
The issue is not even the session being closed when the login is wrong, but rather that it should not even be set if the login was wrong. It should only exist if the login is ok. So, you would…
-
0
votes1
answer291
viewsA: Upload binary data via html-free post
What you really want is to make a remote request through a PHP script by sending a file along with this request. I have two options to offer: Uploading files with the Guzzle Http library One way I…
-
3
votes2
answers413
viewsQ: What is the difference between "memory_get_usage" and "memory_get_peak_usage"?
What is the difference between the functions memory_get_usage and memory_get_peak_usage? The two do the same thing or is there any difference between them?
phpasked Wallace Maxters 102,340 -
5
votes3
answers1740
viewsQ: How do I know how much memory my application uses in PHP?
I wonder if there is any way to know how much my PHP application is consuming memory. For example: I want to know, at the end of the script execution, how much PHP spent on the execution process of…
-
3
votes4
answers366
viewsA: What’s the difference in using sprintf in relation to using variables within the string?
Keep in mind that function sprintf can do much more than simply reserve a space to be filled with an argument. It is much more comprehensive than that. Through this function, you can format numbers…
phpanswered Wallace Maxters 102,340 -
7
votes2
answers753
viewsQ: What is the difference between 301 and 302 redirects?
I would like to know the difference between these two types of redirect code: 301 and 302. I realized that they are called on Google’s Webmaster Tools Permanent redirection and Temporary…
-
6
votes6
answers29816
viewsA: How to create space before or at the end of the text contained between html tags?
Use white-space: pre: div { float:left; white-space: pre; } <div>Texto 1</div><div> texto que quero um espaço antes</div> According to the W3school: pre: Whitespace is…
htmlanswered Wallace Maxters 102,340 -
2
votes1
answer204
viewsA: How to upload to Silex?
The Silex uses the components of Symfony. Therefore, it is possible to use the Symfony Request in order to upload. Example: $app->post('/user/upload', function (Request $request) use ($app) {…
-
2
votes1
answer204
viewsQ: How to upload to Silex?
I did some research to know how to upload files in Silex Framework, but I found nothing about it. Is there any way to do this through Silex? Or would I have to do with nail only with PHP?…
-
3
votes3
answers228
viewsA: What is the default value for the "resize" attribute in a textarea?
Another way to do this is by using the value both. Behold: .my_textarea{ border: 2px solid pink; resize: none; width: 300px; height: 100px; } <textarea class="my_textarea"></textarea>…
-
10
votes3
answers228
viewsQ: What is the default value for the "resize" attribute in a textarea?
How to leave a textarea adjustable after it was set "resize: None"? For example, I have a textarea which has a value defined as resize:none in CSS, but I want to leave the default value by placing…
-
23
votes4
answers31300
viewsA: How to disable resize from textarea?
You can use the attribute resize to define this. To disable changing the size of textarea you set this value to none: <textarea style="resize: none"></textarea> There’s still a way to…
-
7
votes1
answer1482
viewsQ: What is the difference between __init__ and __new__?
What is the difference between the special methods __init__ and __new__ in Python?
-
3
votes1
answer395
viewsQ: Is there any way to use Laravel Eloquent in the Silex microframework?
I’m refactoring a website structure and moving on to the Silex microframework. I wonder if there is any way to use the Laravel Eloquent ORM, to connect with the database. I read in the documentation…
-
3
votes2
answers1982
viewsQ: How do I find out the current version of codeigniter?
How can I to find out the current version of Codeigniter via code? Is there any constant or function that does this?
codeigniterasked Wallace Maxters 102,340 -
1
votes1
answer6033
viewsQ: Codeigniter 2 with variable reference error in PHP version 5.6
I am using version 2.1.3 of Codeigniter and when I open any page the following error is displayed: PHP Error was encountered Severity: Notice Message: Only variable References should be returned by…
-
5
votes3
answers2856
viewsQ: What can cause file_get_contents to give "timeout" error?
I asked that question here, but hardly, because it is a problem that seems to be specific, the solution would be something that would be something generic. But it occurred to me in this question I…
-
2
votes1
answer1459
viewsQ: Timeout when trying to use Composer
When I’m running the remote composer ìnstall or composer update, I am receiving this message after a certain waiting time: The "https://packagist.org/packages.json" file could not be downloaded:…
-
3
votes2
answers1007
viewsA: Blade and Angular JS Incompatibility in Laravel 5
Only as a complement: I also read that I should not use the Blade with Angular, but I find it very practical to use, and I would like to continue, this method is the most correct and recent? There…
-
1
votes1
answer724
viewsA: Ignore http error code when using file_get_contents
The way found to solve this problem was by using a stream_context_create. This function can create a context for the function file_get_contents and so we can configure it to not generate a Warning…
-
9
votes1
answer1015
viewsQ: What is the purpose of __slots__?
What is this property for __slots__? Li in the documentation something about "waste of space", but ultimately I didn’t quite understand the purpose of using __slots__. What it’s for and when I…
-
5
votes2
answers714
viewsQ: How do I know if a value is eternal in Python?
How can I check in Python if a certain value is eternal? What determines that a particular type can be eternal? For example, how to find out this in the case below? a = 1 b = 'Uma string' c = [1, 2,…
-
9
votes2
answers298
viewsQ: How to check if a value is iterable by foreach in PHP?
In PHP, not just arrays are eternal, but also some specific objects. For example, objects that implement the interface Iterator or IteratorAggregate. Another example is stdClass and ArrayObject,…
-
10
votes2
answers298
viewsA: How to check if a value is iterable by foreach in PHP?
In PHP, all array is everlasting. Any object can also be used in foreach, but the behavior cannot be desired, because all public properties are used in the iteration. Thus, you need to define the…
-
16
votes1
answer1890
viewsQ: What is __all__ in Python for?
I’ve seen some code written in Python whose file __init__.py had a variable __all__ with a list assigned. Example: __all__ = ['foo', 'bar'] I’ve noticed that in Python, when things start with…
pythonasked Wallace Maxters 102,340 -
8
votes5
answers23915
viewsQ: How do I know if the variable is an integer in Python?
How can I know if the variable is an integer in Python? I know how to do it in PHP: is_int($variable); // bool(true) But how can I do in Python? Example: numero = 1 #é numero nao_eh_numero = 'texto'…
-
16
votes3
answers44552
viewsQ: How to connect Python to Mysql database?
I wonder how I can make a simple connection to Mysql through a Python script. To do this I need to install some library? Or is there something that comes by default in Python (like in PHP)?…
-
5
votes1
answer2888
viewsQ: In Python is there a debug function equivalent to "print_r" or "var_dump" in PHP?
In Python there is some function for debug equivalent to print_r or var_dump of PHP? For example, in PHP: $valor = 'Hello'; var_dump($valor); string(5)'Hello' In Python would have some similar…
-
12
votes1
answer4201
viewsA: "__" or "Dunder" methods in Python, which are the most used?
Special or magic methods in Python are used to define a class-specific behavior when a certain operation is operated. For example, there are situations where you can define a behavior when the…
python-3.xanswered Wallace Maxters 102,340 -
14
votes2
answers8743
viewsQ: What is the difference between __str__ and __repr__?
What is the difference between the methods __str__ and __repr__? They both do the same thing?
-
2
votes3
answers4250
viewsA: What is the purpose of the "header()" function?
Just to reinforce what has already been said, the function header mounts the http response header that will be sent to the browser. An addendum on function header is that it has an optional second…
-
3
votes2
answers7326
viewsA: What is the correct way to call Python methods?
In Python, every method referring to a class needs to be referenced, in the first parameter, by the pseudo-variable self. def __init__(self): self.mtd([1, 2, 2, 3, 3, 3, 4, 4, 4, 4]) def mtd(self,…
-
11
votes2
answers23324
viewsQ: Count the number of occurrences of a value in a list
I have a list with the following values: numeros = [5, 3, 1, 2, 3, 4, 5, 5, 5] In Python would have some function to count how many times some value repeats? For example: I want to know how many…
-
20
votes5
answers140931
viewsQ: How to limit decimal numbers in Python?
How do I format the number of decimals of a decimal number in Python? For example, I want to display only two decimal places of the following number: numero_decimal = 3.141592653589793 How could I…
-
5
votes2
answers101
viewsQ: How to get an item from a list randomly?
Suppose I have the following list: frutas = ['abacate', 'mamão', 'laranja', 'uva', 'pêra'] I need to capture one of these elements from list randomly. How would I do it in Python?…
-
9
votes2
answers7582
viewsQ: How to capture the last element of a list in Python?
In PHP, to take the last element of a array I can do it like this: $array = array(1, 2, 3); echo end($array); // 3; And in Python? How could I do that with this list: arr = [1, 2, 3]…