Most voted "php-7" questions
PHP7 is a new version of the language, which has new features like: Several errors are now treated as exceptions. Removed the old SAPI API and extensions Null coalescing Operator (`?`) Combined comparison Operator (`<=>`) Return typed in methods. Declaration of scalar types. Anonymous classes Use this tag only when the question has any problem or doubt about the resources cited.
Learn more…198 questions
Sort by count of
-
20
votes5
answers2497
viewsWhat 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…
-
14
votes4
answers3299
viewsTyping the return in PHP 7. What are the advantages?
I was giving a test in PHP 7 and I checked that the same now accepts to define which type of data will be returned. Here are some tests: Defining the instance to be returned function test_object():…
-
13
votes2
answers995
viewsPHP 7 has argument typing and return, but is it optional. Is that good or bad?
I would not like to raise here a controversial issue regarding the PHP 7 language, which was released recently, but only understand a few points regarding typing. Come on: In versions prior to PHP…
-
10
votes2
answers1121
viewsPHP7 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…
-
9
votes2
answers1049
viewsPHP 7 already has stable version for production?
I am thinking of building a new version of the current system of my company, it is with PHP in version 5.5.9. PHP 7 already has stable version to work in production? I saw many posts on the Internet…
-
9
votes2
answers3537
viewsWhat is the function of the «??» operator (two questions) in PHP?
Analyzing a script PHP at a certain point I came across this line $valor = $_GET['id'] ?? 1; What is the interpretation of this code? What does it do?
-
9
votes1
answer147
viewsPHP 7 - Why does a method that returns the primitive String type not generate an error when returning a Boolean value?
PHP 7 - Why a method that returns the primitive type String, does not generate error when returning a value Boolean? <?php class Foo { public function bar() : string { return true; } } $Foo = new…
-
8
votes2
answers2552
viewsWhich IDE supports PHP 7?
Does anyone know of an IDE (or simpler code editor) with PHP 7 support? I use Netbeans, but it seems that support for PHP 7 in it can be added in future versions, but it is still uncertain. I’m…
-
6
votes4
answers99
viewsSimplify value localization in arrays in PHP
I have the arrays as below: $records = [ ["id"=>"1", "name"=>"Alpha"], ["id"=>"2", "name"=>"Bravo"], ["id"=>"3", "name"=>"Charlie"], ["id"=>"4", "name"=>"Delta"],…
-
5
votes2
answers204
viewsWhat 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…
-
5
votes1
answer104
viewsIn PHP 7, can the class method contain a keyword name? Is that good or bad?
PHP 7 has launched a number of innovations for the PHP language. I even noticed that classes can now have keyword named methods. The strange thing is that classes cannot have, but methods can (see!)…
-
5
votes3
answers148
viewsVariable is not updated in constructor
I’m learning OO and venturing into PHP, only I came across something that I think in theory should work, but in practice does not work. <?php class Users{ public $name; public $idade; public…
-
5
votes1
answer1985
viewsProblem using $_SESSION in PHP 7.1.10
I have two servers running PHP, one in version 5.4.45 and another 7.1.10. When running the files below at the same url, only the older version of PHP displays the values of the "test" session. In…
-
4
votes2
answers480
viewsRemove the original image from the server after Wordpress generates the thumbnails
I need to remove the original image that gives rise to Wordpress thumbnails after thumbnails are generated. I have 3 sizes of Thumbs that I use, but to avoid that the server is left with unnecessary…
-
4
votes2
answers268
viewsHow do I update PHP 7.0.0RC1 to version 7.0 already released in centos?
Good morning, How do I update PHP 7.0.0RC1 to version 7.0 already released in centos? Thank you
-
4
votes1
answer9659
views502 Bad Gateway - Linux, php7, Nginx. How to resolve this error?
I am having a 502 error that represents some configuration on the server, when I try to open a site using linux, Nginx and php7. Researching some other POSTS, link about the same error I see that…
-
4
votes2
answers98
viewsIs Try-with-Resource in PHP?
Exists in PHP something similar to Try with Resource java? Or I have to close resources in the finally even?
-
4
votes2
answers49
views -
3
votes2
answers389
viewsAccess the main class instance from an anonymous one in PHP 7
I’m trying to access the instance of the class where contains an anonymous as we do in Java, example: JAVA class MyClass { private String prop = "test"; public void test() { new Runnable() { public…
-
3
votes1
answer511
viewsFailed to register NULL value in database - PHP7
Good night to you all, I am a beginner and I am developing a registration system for CATEGORIES and SUBCATEGORIES in PHP7 and MYSQL; The logic I used to register Categories and Subcategories is:…
-
3
votes1
answer93
viewsWhat exactly is the Datetime::createFromImmutable() method for?
What exactly is the method for DateTime::createFromImmutable()? Implemented according to the release note of version 7.3.0 of PHP.
-
3
votes1
answer71
viewsHow to set 'default' keys and values for array passed as parameter in PHP?
I did a function that takes several arguments, and I decided to pass them by a array to be executed. Ex: public function funcTeste(array $dados){ return \count($dados); } But this array must have a…
-
3
votes1
answer438
viewsHow to validate a numerical expression with a regular expression?
I need within my application in PHP7 to validate a numerical expression with a regular expression, the case is that I almost succeeded but I ran into a problem. Non-significant zeros within the…
-
2
votes1
answer103
viewsSelf 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…
-
2
votes1
answer185
viewsDoubt about Sessions in the IC
According to : $config['sess_expiration'] = 7200; The session will be destroyed after 7200 seconds, however I wanted to know if when I update the page or access another page of my system, that time…
-
2
votes3
answers2082
viewsAfter "apt-get dist-upgrade" command, PHP 7 was installed. How to go back to 5?
I use Ubuntu 14.04. And when I went to execute this command apt-get dist-upgrade here on my machine, he installed PHP 7. I’ve already removed PHP 7 like this: apt-get purge php.* But when I do so:…
-
2
votes1
answer1366
viewsPHP7 does not work with SQL Server 2014
I have a project running in Xampp with PHP 5.6 and SQL Server 2014 Express. I’m trying to migrate the project to PHP 7.1.0 but is giving error as shown below. I copied the dll to the ext folder of…
-
2
votes2
answers483
viewsWhy 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…
-
2
votes1
answer881
viewsProblem installing OCI8 in a Vagrant vm
I created a VM with the Laravel Homestead I need to install the IOC8 in it: I turn the remote sudo pecl install oci8 as you report here But I get that mistake: ERROR: `/tmp/Pear/temp/oci8/configure…
-
2
votes1
answer472
viewsTernary operator " ?: "
I recently got into a discussion with colleagues about the more compact functionality of the if ternary ( x ?: 10) and some of them said it would be removed in php 7. I did a web search and found…
-
2
votes2
answers606
viewsEmpty function return
Could someone tell me why my insert2 function is returning null after insertion? she should be returning the string with the success message. <?php require_once 'conexao.php'; $con = new…
-
2
votes0
answers142
viewsimage does not appear by rule in . htaccess
I have my .htaccess in the form below: <IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -t [OR] RewriteCond %{REQUEST_FILENAME}…
-
2
votes1
answer542
viewsRegular Expression to separate Substring from String
I have the following sentence: "SUZANO ZANO ZMES ZDIA ZANO_MES" and I need to remove from it only "ZANO ZMES ZDIA", recalling that the ZANO of SUZANO and of ZANO_MES cannot be related. I used the…
-
2
votes1
answer66
viewsError using Fuelphp in version 7
I wonder if anyone has ever encountered a similar error when using the Fuelphp framework, in version 1.7 with PHP 7. This is popping the following message, before entering the application: Fatal…
-
2
votes1
answer62
viewsHow to return a data collection using Doctrine Resultsetmapping?
I have the following script that is functional: SELECT r.coluna_1 as Coluna_1, e.coluna_1 as Coluna_2, FROM produto r INNER JOIN empresa e ON r.id_empresa = e.id_empresa WHERE r.id_tipo = 'N' AND…
-
2
votes1
answer1358
viewsError in PHP ... Fatal error: Uncaught Error: Call to a Member Function Modify() on Boolean
Guys I have a PHP script that adds another 10 days on a date. The script was working wonderfully well, however, a few days ago I started getting the following error: PHP Fatal error: Uncaught Error:…
-
2
votes1
answer74
viewsProblems with date transformation function
$data = $_POST["data"]; // Recebe a variável com a data, e cria um objeto DateTime a partir do formato especificado. $objetoData = DateTime::createFromFormat('d/m/Y', $data); // Reformata a data do…
-
2
votes0
answers55
viewsQuery return interaction with Array
SQL: SELECT t.idMembro, t.nomeTabela from ( SELECT idMembro as idMembro, 'pastores' as nomeTabela FROM pastores union SELECT idLider as idMembro, 'redes' as nomeTabela FROM redes union SELECT…
-
2
votes1
answer514
viewsFractions of 15 minutes in the PHP time log
I have a billing system for hours which I am trying to make charges for fractions of 15 min. It takes the difference of the time of entry and exit and adds the remaining time, example: Check-in…
-
2
votes1
answer219
views -
2
votes1
answer224
viewsTimeout to Upload FTP file in PHP
Friends, I am trying to develop the upload of files to FTP by PHP. When running it it successfully connects to the FTP server. However, the page keeps loading until a timeout and does not finish…
-
2
votes0
answers55
viewsPHP error with PDO and SQLITE, Call to a Member Function execute() on bool
Hello, can anyone see why this error is apparently all right function verificarImportados(){ define("DB_DSN", "sqlite:host=localhost;dbname=dbXML.db"); define("DB_USERNAME", " ");…
-
2
votes1
answer38
viewsWhy does Phpunit not consider early return in method in code Coverage?
I have a code that I am testing with Phpunit being that in the tested method there is an early return with null under certain condition. However, Phpunit does not consider this part of the code to…
-
1
votes1
answer804
viewsHow to install PHP7 in *Unix
I decided to test a Unix-like system (Linux Mint) to learn more, and I need to install PHP7, because the Phptherightway sent. I already installed apache2 via Terminal and Mysql. I know there is a…
-
1
votes1
answer262
viewsGET 500 (Internal error) PHP
Good morning, I wrote a PHP class <?php private $v; private $v2; private $v3; public function __construct(){ printf("Objeto criado com sucesso!"); } public function setValor(){ $this->$v =…
-
1
votes2
answers1970
viewsAccentuation problem when migrating to PHP7
I’m wearing a leotard latin1 in the bank columns and iso-8859-1 on the pages, while it was on PHP5 it worked normal, but when migrating to PHP7 the accents began to give problems appearing this � in…
-
1
votes1
answer199
viewsCreate Dockerfile for Zend Expressive
Hello folks I’m having a hard time running the expressive zend with the Docker. I have other projects that work perfectly with Docker but when I try to develop with zend expressive, I can’t, it…
-
1
votes1
answer319
viewsDoubt about autoload php
About autoload I studied about: Autoload for classes in the same folder function __autoload($nomeClass) { require_once ("$nomeClass.php"); } Autoload for classes in specific folders…
-
1
votes2
answers1875
viewsimagecreatefrompng() function does not exist - Undefined Function error
I am trying to save a png image, and when I run the error script: Fatal error: Uncaught Error: Call to undefined function imagecreatefrompng() But from what I’ve seen, this function is native to…
-
1
votes4
answers3077
viewsHow to prevent refresh after Ubmit on the same page?
I have a basic HTML form that sends the data through the POST method to the same page, that is, I do Submit to the page itself. As this page has Javascript actions, after this Ubmit the page reset,…