Type hinting for properties in PHP 7?

PHP 7.4 will support typed properties like so: class Person { public string $name; public DateTimeImmutable $dateOfBirth; } PHP 7.3 and earlier do not support this, but there are some alternatives. You can make a private property which is accessible only through getters and setters which have type declarations: class Person { private $name; public … Read more

PHP 7 interfaces, return type hinting and self

editorial note: the answer below is outdated. as php PHP7.4.0, the following is perfectly legal: <?php Interface I{ public static function init(?string $url): self; } class C implements I{ public static function init(?string $url): self{ return new self(); } } $o = C::init(“foo”); var_dump($o); 3v4l: https://3v4l.org/VYbGn original answer: self does not refer to the instance, … Read more

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

What is the difference between fastcgi and fpm?

FPM is a process manager to manage the FastCGI SAPI (Server API) in PHP. Basically, it replaces the need for something like SpawnFCGI. It spawns the FastCGI children adaptively (meaning launching more if the current load requires it). Otherwise, there’s not much operating difference between it and FastCGI (The request pipeline from start of request … Read more

PHP 7: Missing VCRUNTIME140.dll

On the side bar of the PHP 7 alpha download page, it does say this: VC9, VC11 & VC14 More recent versions of PHP are built with VC9, VC11 or VC14 (Visual Studio 2008, 2012 or 2015 compiler respectively) and include improvements in performance and stability. The VC9 builds require you to have the Visual … Read more

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