apache - Enabling 'strict_types' globally in PHP 7 -
i'm migrating website php5 php7, , i've started using strict typing feature added. requires me begin files following line:
<?php declare(strict_types=1); // other code here // ...
so wondering, there way enable strict_types
globally using php.ini
or apache configuration file don't have write line every time, , if how enable this?
this deliberately not possible, because implementation adopted after extremely long discussion of scalar type hints one: https://wiki.php.net/rfc/scalar_type_hints_v5
it explicitly gives choice of how scalar types checked caller of function, not author, that:
- if write library scalar type hints, functions guaranteed parameter types requested, if called code not written in strict mode (the types coerced instead)
- if write library , want traditional weak typing, can still make use of libraries use type hints (because don't force perform strict type checking)
- contrarily, if write library , want strict typing for functions call, don't have require users of library enable strict typing
- built-in functions work same way user-defined ones, , existing code runs same default
- if turn on strict typing, need change code handle correctly anyway
it's therefore tell php files have been written use strict type mode, , haven't; , way using declare
statement.
Comments
Post a Comment