Tags
Asked 3 years ago
13 Jul 2021
Views 225
Frances

Frances posted

What is the difference between PHP 5 and PHP 7 ?

What is the difference between PHP 5 and PHP 7 ?
noob

noob
answered Aug 19 '21 00:00

Following function removed from PHP 7 onward :
1.
constructors (methods that have the same name as the class they are defined in) are deprecated in PHP 7 , If someone try to construct class by the same name as the class they are defined in PHP 7 , it generates error as below :
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP;



2.
ldap_sort() is deprecated in PHP 7 .
capture_session_meta SSL context option has been deprecated.
password_hash() function has been deprecated .
Static calls to methods that are not declared static are deprecated .


PHP 7 some functions are changed which is listed below :

1 . In PHP 7 as compare to PHP 5, debug_zval_dump() [/b ] function prints "int" instead of "long", and "float" instead of "double"

2. In PHP 7 , [b] dirname()
function optionally takes a second parameter, depth, to get the name of the directory depth levels up from the current directory. in PHP 5 dirname() function dont have depth as second parameter

3. In PHP 7 , getrusage() function is now supported on Windows which is not at PHP 5 .

4. In PHP 7 , mktime() and gmmktime() functions no longer accept is_dst parameter. On other hand in PHP 5 mktime() and gmmktime() functions accept is_dst parameter

5. PHP 5 have preg_replace() function which no longer supported in PHP 7 . preg_replace_callback() should be used in PHP 7.

6. in PHP 7 , setlocale() function no longer accepts category passed as string. LC_* constants must be used instead.

7. in PHP 7 , exec() , system() and passthru() functions have NULL byte protection now.
a resource instead of an

8. shmop_open() returns an int in PHP 5 which is changed to resource instead , which has to be passed to shmop_size(), shmop_write(), shmop_read(), shmop_close() and shmop_delete().

9. substr() and iconv_substr() now return an empty string, if string is equal to start characters long in PHP 7.

10 . xml_parser_free() function was used to free the parser resource in PHP 5 which is no longer sufficient to free the parser resource.


Following is the new function in PHP 7 :


Closure::call()

random_bytes()
random_int()

error_clear_last()

Generator::getReturn()

gmp_random_seed()

intdiv()

preg_replace_callback_array()

gc_mem_caches()
get_resources()

posix_setrlimit()

ReflectionParameter::getType()
ReflectionParameter::hasType()
ReflectionFunctionAbstract::getReturnType()
ReflectionFunctionAbstract::hasReturnType()

ZipArchive::setCompressionIndex()
ZipArchive::setCompressionName()

inflate_add()
deflate_add()
inflate_init()
deflate_init()

In addition :
PHP 7 adds support for return type declarations.
PHP 7 adds spaceship operator.
PHP 7 adds Scalar type declarations .
PHP 7 adds Null coalescing operator .
PHP 7 adds Constant arrays using define().
PHP 7 adds Anonymous classes support .


Post Answer