Deploying PHP 7
Deploying PHP 7 Confoo Montreal Feb.25, 2016 http://talks.php.net/confoo16a Rasmus Lerdorf @rasmus Top-5 Things that might bite you For the full list see php.net/migration70 Left-to-right semantics for complicated expressions $$foo['bar']['baz'] // interpreted as ($$foo)['bar']['baz'] $foo->$bar['baz'] // interpreted as ($foo->$bar)['baz'] $foo->$bar['baz']() // interpreted as ($foo->$bar)['baz']() Foo::$bar['baz']() // interpreted as (Foo::$bar)['baz']() To restore the previous behaviour add explicit curly braces: ${$foo['bar']['baz']} $foo->{$bar['baz']} $foo->{$bar['baz']}() Foo::{$bar['baz']}() Detection: phan or unit test failures Removed support for /e (PREG_REPLACE_EVAL) modifier echo preg_replace('/:-:(.*?):-:/e', '$this->pres->\\1', $text); Change to: echo preg_replace_callback( '/:-:(.*?):-:/', function($matches) { return $this->pres->{$matches[1]}; // Careful! }, $text); Detection: grep, warnings in logs or unit test failures $HTTP_RAW_POST_DATA global removed if (empty($GLOBALS['HTTP_RAW_POST_DATA']) && strpos($_SERVER['CONTENT_TYPE'], 'www-form-urlencoded') === false) { $GLOBALS['HTTP_RAW_POST_DATA'] = file_get_contents("php://input"); } Detection: grep, warnings in logs or unit test failures session.lazy_write enabled by default session.lazy_write = 0 Detection: Can cause out-of-band session read timing issues Invalid octal literals now produce a parse error echo 05678; // PHP 5.x outputs 375 Parse error: Invalid numeric literal in file.php on line 2 Detecting parse errors is easy: php -l Static Analysis github.com/etsy/phan % phan -h Usage: ./phan [options] [files...] -f, --file-list <filename> A file containing a list of PHP files to be analyzed -r, --file-list-only A file containing a list of PHP files to be analyzed to the exclusion of any other directories or files passed in.
This is useful when running Phan from a stored state file and passing in a small subset of files to be re-analyzed. -l, --directory <directory> A directory to recursively read PHP files from to analyze -3, --exclude-directory-list <dir_list> A comma-separated list of directories for which any files included from that directory will not be analysis. Note that adding a directory here will not cause its files to be parsed. -d, --project-root-directory Hunt for a directory named .phan in the current or parent directory and read configuration file config.php from that path. -m <mode>, --output-mode Output mode from 'text', 'json', 'codeclimate', or 'checkstyle' -o, --output <filename> Output filename -p, --progress-bar Show progress bar -a, --dump-ast Emit an AST for each file rather than analyze -e, --expand-file-list Expand the list of files passed in to include any files that depend on elements defined in those files.
This is useful when running Phan from a state file and passing in just the set of changed files. -q, --quick Quick mode - doesn't recurse into all function calls -b, --backward-compatibility-checks Check for potential PHP 5 -> PHP 7 BC issues -i, --ignore-undeclared Ignore undeclared functions and classes -y, --minimum-severity <level in {0,5,10}> Minimum severity level (low=0, normal=5, critical=10) to report. Defaults to 0. -c, --parent-constructor-required Comma-separated list of classes that require parent::__construct() to be called -x, --dead-code-detection Emit issues for classes, methods, functions, constants and properties that are probably never referenced and can possibly be removed. -j, --processes <int> The number of parallel processes to run during the analysis phase.
Defaults to 1. -z, --signature-compatibility Analyze signatures for methods that are overrides to ensure compatiiblity with what they're overriding. -h,--help This help information % phan -i -b display.php display.php:416 CompatError expression may not be PHP 7 compatible echo preg_replace('/:-:(.*?):-:/e', '$this->pres->\\1', $text); echo preg_replace_callback( '/:-:(.*?):-:/', function($matches) { return $this->pres->$matches[1]; // Oops! }, $text); echo preg_replace_callback( '/:-:(.*?):-:/', function($matches) { return $this->pres->{$matches[1]}; // Ok }, $text); % git clone https://github.com/Seldaek/monolog.git % cd monolog % find . -name '*.php' | grep -v test > filelist.txt % phan -i -f filelist.txt ./src/Monolog/Handler/ChromePHPHandler.php:178 PhanTypeMismatchReturn Returning type int but headersAccepted() is declared to return bool ./src/Monolog/Handler/ElasticSearchHandler.php:124 PhanTypeMismatchArgumentInternal Argument 3 (previous) is \elastica\exception\exceptioninterface but \runtimeexception::__construct() takes \runtimeexception|\throwable ./src/Monolog/Handler/FirePHPHandler.php:81 PhanTypeMismatchReturn Returning type array but createRecordHeader() is declared to return string ./src/Monolog/Handler/FirePHPHandler.php:153 PhanTypeMismatchArgumentInternal Argument 1 (array_arg) is string but \current() takes array ./src/Monolog/Handler/FirePHPHandler.php:154 PhanTypeMismatchArgumentInternal Argument 1 (array_arg) is string but \current() takes array ./src/Monolog/Handler/FirePHPHandler.php:154 PhanTypeMismatchArgumentInternal Argument 1 (array_arg) is string but \key() takes array ./src/Monolog/Handler/FlowdockHandler.php:70 PhanTypeMissingReturn Method \monolog\handler\flowdockhandler::getdefaultformatter is declared to return \monolog\formatter\formatterinterface but has no return value ./src/Monolog/Handler/GelfHandler.php:55 PhanTypeMismatchProperty Assigning null to property but \monolog\handler\gelfhandler::publisher is \gelf\imessagepublisher|\gelf\publisher|\gelf\publisherinterface ./src/Monolog/Handler/MandrillHandler.php:49 PhanSignatureMismatch Declaration of function send($content, array $records) should be compatible with function send(string $content, array $records) defined in ./src/Monolog/Handler/MailHandler.php:46 ./src/Monolog/Handler/NativeMailerHandler.php:117 PhanSignatureMismatch Declaration of function send($content, array $records) should be compatible with function send(string $content, array $records) defined in ./src/Monolog/Handler/MailHandler.php:46 ./src/Monolog/Handler/RedisHandler.php:41 PhanTypeMismatchDefault Default value for int $capSize can't be bool ./src/Monolog/Handler/SocketHandler.php:115 PhanTypeMismatchProperty Assigning float to property but \monolog\handler\sockethandler::timeout is int ./src/Monolog/Handler/SocketHandler.php:126 PhanTypeMismatchProperty Assigning float to property but \monolog\handler\sockethandler::writingTimeout is int ./src/Monolog/Handler/SocketHandler.php:218 PhanTypeMismatchArgumentInternal Argument 2 (seconds) is float but \stream_set_timeout() takes int ./src/Monolog/Handler/SocketHandler.php:218 PhanTypeMismatchArgumentInternal Argument 3 (microseconds) is float but \stream_set_timeout() takes int ./src/Monolog/Handler/SocketHandler.php:274 PhanTypeMismatchProperty Assigning resource to property but \monolog\handler\sockethandler::resource is null ./src/Monolog/Handler/StreamHandler.php:65 PhanTypeMismatchProperty Assigning null to property but \monolog\handler\streamhandler::stream is resource|string ./src/Monolog/Handler/StreamHandler.php:86 PhanTypeMismatchProperty Assigning null to property but \monolog\handler\streamhandler::stream is resource|string ./src/Monolog/Handler/StreamHandler.php:105 PhanTypeMismatchProperty Assigning array|string to property but \monolog\handler\streamhandler::errorMessage is null ./src/Monolog/Handler/SwiftMailerHandler.php:43 PhanSignatureMismatch Declaration of function send($content, array $records) should be compatible with function send(string $content, array $records) defined in ./src/Monolog/Handler/MailHandler.php:46 ./src/Monolog/Handler/SyslogUdp/UdpSocket.php:38 PhanTypeMismatchProperty Assigning null to property but \monolog\handler\syslogudp\udpsocket::socket is resource ChromePHPHandler.php:178 PhanTypeMismatchReturn Returning type int but headersAccepted() is declared to return bool /** * Verifies if the headers are accepted by t
The rest of this page is on the live site.