Enabling ‘strict_types’ globally in PHP 7

This is deliberately not possible, because the implementation adopted after an extremely long discussion of scalar type hints was this one: https://wiki.php.net/rfc/scalar_type_hints_v5 It introduces two modes for scalar type parameters, which both guarantee that the function receiving the parameters gets the types that it requires in its signature. However, it provides two modes for how … Read more

install php70-gd on ubuntu

PHP7 packages for Ubuntu including php7.0-gd can be installed via PPA for PHP by Ondřej Surý: sudo add-apt-repository ppa:ondrej/php sudo apt-get update Next, install the desired version: sudo apt-get install php7.0-gd # or sudo apt-get install php7.1-gd # or sudo apt-get install php7.2-gd # or sudo apt-get install php7.3-gd # or sudo apt-get install php7.4-gd … Read more

PHP 7 RC3: How to install missing MySQL PDO

For thoses running Linux with apache2 you need to install php-mysql apt-get install php-mysql or if you are running ubuntu 16.04 or higher just running the following command will be enought, no need to edit your php.ini file apt-get install php7.2-mysql If you are running ubuntu 15.10 or below: Edit your php.ini file, it’s located … Read more

Silence “Declaration … should be compatible” warnings in PHP 7

1. Workaround Since it is not always possible to correct all the code you did not write, especially the legacy one… if (PHP_MAJOR_VERSION >= 7) { set_error_handler(function ($errno, $errstr) { return strpos($errstr, ‘Declaration of’) === 0; }, E_WARNING); } This error handler returns true for warnings beginning with Declaration of which basically tells PHP that … Read more

PHP 7 simpleXML

I had the same problem and I’m using Ubuntu 15.10. In my case, to solve this issue, I installed the package php7.0-xml using the Synaptic package manager, which include SimpleXml. So, after restart my Apache server, my problem was solved. This package came in the Debian version and you can find it here: https://packages.debian.org/sid/php7.0-xml.

Function return type hinting for an array of objects in PHP7

You can type hint this way using docblocks. PHP editor (IDE) like PhpStorm supports this very well and will properly resolve the class when iterating over such array. /** * @return YourClass[] */ public function getObjects(): array PHPStorm also supports nested arrays: /** * @return YourClass[][] */ public function getObjects(): array Newer versions of PHPStorm … Read more

Is it possible to specify multiple return types on PHP 7?

As of PHP 8+, you may use union types: function test(): FailObject|SuccessObject {} Another way, available in all versions since PHP 4, is for the two objects to share an interface. Example: interface ReturnInterface {} class FailObject implements ReturnInterface {} class SuccessObject implements ReturnInterface {} function test(): ReturnInterface {} In this example, ReturnInterface is empty. … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)