C#’s null coalescing operator (??) in PHP

PHP 7 adds the null coalescing operator: // Fetches the value of $_GET[‘user’] and returns ‘nobody’ // if it does not exist. $username = $_GET[‘user’] ?? ‘nobody’; // This is equivalent to: $username = isset($_GET[‘user’]) ? $_GET[‘user’] : ‘nobody’; You could also look at short way of writing PHP’s ternary operator ?: (PHP >=5.3 only) … Read more

“Call to undefined function mysql_connect()” after upgrade to php-7 [duplicate]

From the PHP Manual: Warning This extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide. Alternatives to this function include: mysqli_connect() PDO::__construct() use MySQLi or PDO <?php $con = mysqli_connect(‘localhost’, ‘username’, ‘password’, ‘database’);

Why I am suddenly getting a “Typed property must not be accessed before initialization” error when introducing properties type hints?

Since PHP 7.4 introduces type-hinting for properties, it is particularly important to provide valid values for all properties, so that all properties have values that match their declared types. A property that has never been assigned doesn’t have a null value, but it is on an undefined state, which will never match any declared type. … Read more

mcrypt is deprecated, what is the alternative?

It’s best practice to hash passwords so they are not decryptable. This makes things slightly more difficult for attackers that may have gained access to your database or files. If you must encrypt your data and have it decryptable, a guide to secure encryption/decryption is available at https://paragonie.com/white-paper/2015-secure-php-data-encryption. To summarize that link: Use Libsodium – … Read more