Installing the PHP 7 MongoDB Client/Driver?

The Mongo extension for PHP Version 5.99.99 or older has been superseded: https://pecl.php.net/package/mongo Use the newer one for PHP Version 7.99.99 or older instead: https://pecl.php.net/package/mongodb You can install a PECL/PEAR extension automatically: pecl install mongodb or manually. The classes have been changed too: new \MongoClient(); // legacy class! see http://php.net/manual/en/book.mongo.php new \MongoDB\Driver\Manager(); // new classes! … Read more

Linux – PHP 7.0 and MSSQL (Microsoft SQL)

Microsoft has PHP Linux Drivers for SQL Server for PHP 7 and above on PECL. These are production ready. To download them, follow these steps: Ubuntu 16.04: sudo su curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add – curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list exit sudo apt-get update sudo ACCEPT_EULA=Y apt-get install -y msodbcsql mssql-tools unixodbc-dev sudo pecl install sqlsrv … Read more

PHP 7 and strict “resource” types

PHP does not have a type hint for resources because No type hint for resources is added, as this would prevent moving from resources to objects for existing extensions, which some have already done (e.g. GMP). However, you can use is_resource() within the function/method body to verify the passed argument and handle it as needed. … 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

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

Parse error: Invalid numeric literal

This comes from the changes made to how integers, specifically octals, are handled in PHP7 (as oppsoed to PHP5). From the documentation (from PHP7 migration) Invalid octal literals Previously, octal literals that contained invalid numbers were silently truncated (0128 was taken as 012). Now, an invalid octal literal will cause a parse error. From the … Read more

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