php7 – benefits and drawbacks
Post on 19-Feb-2017
149 Views
Preview:
TRANSCRIPT
ABOUT ME@drgomesp
github.com/drgomesp twitter.com/drgomesp
facebook.com/drgomesp
PHP 7 – MAIN CHANGES
➤ PHPNG (next generation of Zend Engine)
➤ Scalar type declarations
➤ Return type declarations
➤ Spaceship operator
➤ Anonymous classes
➤ Generator return expressions
➤ Generator delegation
➤ Performance
➤ Error handling (Exceptions)
➤ Extension API changes
➤ …
SCALAR TYPE DECLARATIONS
➤ Types ➤ bool ➤ float ➤ int ➤ string
➤ Coercive and Strict modes
this throws an exception in strict mode!!!
DRAWBACKS
➤ If the return is omitted, the return value is NULL
➤ When overriding, child's method must match return type declaration of the parent. If parent does not define the type, the child method may define it.
SPACESHIP OPERATOR
➤ Used for comparing two expressions
➤ Returns -1, 0 or 1, respectively less than, equal to or greater than
➤ Extremely useful for functions like usort()
ANONYMOUS CLASSES
➤ Works via the new class syntax
➤ Useful for classes that don’t need to be documented
➤ Useful for classes that are used once during execution
➤ Supports use of traits
➤ Reflection works with ReflectionClass::isAnonymous()
GENERATOR RETURN EXPRESSIONS
➤ Enables a final expression to be returned from within a generator
➤ Values can be fetched through the Generator::getReturn() method, which may only be used once the generator has finishing yielding
➤ Useful for the client code executing the generator. Instead of forcing the client to check whether the final value has been yielded, and being able to handle that value specifically.
GENERATOR DELEGATION
➤ Generators can now delegate to other generators, through the usage of the yield from construct.
EXTENSION API CHANGES
➤ Extensions must be refactored to be compatible with PHP7
➤ https://wiki.php.net/phpng-upgrading
➤ zend_rsrc_list_entry => zend_resource
➤ ZEND_FETCH_RESOURCE() => zend_fetch_resource()
➤ IS_BOOL => IS_TRUE and IS_FALSE
➤ and MUCH MORE ➤ https://github.com/gophp7/gophp7-ext/wiki/extensions-catalog
top related