php / doc-en

English PHP documentation
504 stars 736 forks source link

Undocumented changes for get_class_vars and get_parent_class in migration manual to PHP8.0 #1175

Open simics-ja opened 2 years ago

simics-ja commented 2 years ago

Migration manual from PHP7.4.x to PHP8.0 forgets to write change about the return value of get_class_vars and get_parent_class. These functions return false if an invalid class name is given in PHP7.4 or prior, but they throw TypeError in PHP8.0.

7.4: https://github.com/php/php-src/blob/PHP-7.4.27/Zend/tests/get_class_vars_001.phpt 8.0: https://github.com/php/php-src/blob/PHP-8.0/Zend/tests/get_class_vars_001.phpt#L40

This problem exists in all languages.

Note: This change is only written in the section of get_parent_class document. I think this change should be written in get_class_vars.

cmb69 commented 2 years ago

This is a general issue, affecting almost all functions, and it is already documented:

If the parameters given to a function are not what it expects, such as passing an array where a string is expected, the return value of the function is undefined. In this case it will likely return null but this is just a convention, and cannot be relied upon. As of PHP 8.0.0, a TypeError exception is supposed to be thrown in this case.

We should add a general note about that in the migration guide, and need to update the return values sections of get_class_vars() and get_parent_class().