<slide title="" section="php7">

<image filename="php7trans-200.png" />

<blurb fontsize="1.1em" align="left">✔ engine improvements</blurb>
<list>
<bullet fontsize="1em" type="none">100%+ performance gain on most real-world applications</bullet>
<bullet fontsize="1em" type="none">Lower memory usage</bullet>
<bullet fontsize="1em" type="none">Native thread local storage</bullet>
</list>

<break lines="1" section="php7pcache1"/>
<blurb fontsize="1.1em" align="left">✔ Persistent secondary file-based cache for OPCache</blurb>
<image filename="pcache.png" />

<break lines="1" section="php7pcache2"/>
<image filename="deploycache.png" />

<break lines="1" section="php7pcache3"/>
<example fontsize="1.1em" result='0' title="" type="ini"><![CDATA[
; --enable-opcache-file
; php.ini
opcache.file_cache=/var/tmp

; php-cli.ini
opcache.enable_cli=1
opcache.file_cache=/var/tmp
opcache.file_cache_only=1
]]></example>
<example fontsize="1em" result='0' title="" type="shell nohighlight"><![CDATA[
$ time composer >/dev/null
real	0m0.040s
user	0m0.032s
sys	0m0.004s

$ time composer >/dev/null
real	0m0.019s
user	0m0.016s
sys	0m0.000s

$ time php -d opcache.enable=0 /usr/local/bin/composer >/dev/null
real	0m0.033s
user	0m0.032s
sys	0m0.000s
]]></example>

<break lines="1" section="php7pcache4"/>
<example fontsize="0.78em" result='0' title="" type="shell nohighlight"><![CDATA[
/var/tmp
├── 7eeb6fe88104116c27c5650ddd83abf0
│   └── usr
│       └── local
│           └── bin
│               └── composer.bin
└── 7eeb6fe88104116c27c5650ddd83abf0phar:
    └── usr
        └── local
            └── bin
                └── composer
                    ├── bin
                    │   └── composer.bin
                    ├── src
                    │   ├── bootstrap.php.bin
                    │   └── Composer
                    │       ├── Command
                    │       │   ├── AboutCommand.php.bin
                    │       │   ├── ArchiveCommand.php.bin
                    │       │   ├── ClearCacheCommand.php.bin
                    │       │   ├── Command.php.bin
                    │       │   ├── ConfigCommand.php.bin
                    │       │   ├── CreateProjectCommand.php.bin
                    │       │   ├── DependsCommand.php.bin
                    │       │   ├── DiagnoseCommand.php.bin
                    │       │   ├── DumpAutoloadCommand.php.bin
                    │       │   ├── GlobalCommand.php.bin
                    │       │   ├── Helper
                    │       │   │   └── DialogHelper.php.bin
                    │       │   ├── HomeCommand.php.bin
                    │       │   ├── InitCommand.php.bin
                    │       │   ├── InstallCommand.php.bin
                    │       │   ├── LicensesCommand.php.bin
                    │       │   ├── RemoveCommand.php.bin
                    │       │   ├── RequireCommand.php.bin
                    │       │   ├── RunScriptCommand.php.bin
                    │       │   ├── SearchCommand.php.bin
                    │       │   ├── SelfUpdateCommand.php.bin
                    │       │   ├── ShowCommand.php.bin
                    │       │   ├── StatusCommand.php.bin
                    │       │   ├── UpdateCommand.php.bin
                    │       │   └── ValidateCommand.php.bin
                    │       ├── Composer.php.bin
                    │       ├── Console
                    │       │   └── Application.php.bin
                    │       ├── Factory.php.bin
                    │       ├── IO
                    │       │   ├── BaseIO.php.bin
                    │       │   ├── ConsoleIO.php.bin
                    │       │   └── IOInterface.php.bin
                    │       ├── Package
                    │       │   ├── BasePackage.php.bin
                    │       │   └── PackageInterface.php.bin
                    │       ├── Script
                    │       │   └── ScriptEvents.php.bin
                    │       └── Util
                    │           └── ErrorHandler.php.bin
                    └── vendor
                        ├── autoload.php.bin
                        ├── composer
                        │   ├── autoload_classmap.php.bin
                        │   ├── autoload_namespaces.php.bin
                        │   ├── autoload_psr4.php.bin
                        │   ├── autoload_real.php.bin
                        │   └── ClassLoader.php.bin
                        └── symfony
                            └── console
                                └── Symfony
                                    └── Component
                                        └── Console
                                            ├── Application.php.bin
                                            ├── Command
                                            │   ├── Command.php.bin
                                            │   ├── HelpCommand.php.bin
                                            │   └── ListCommand.php.bin
                                            ├── Descriptor
                                            │   ├── ApplicationDescription.php.bin
                                            │   ├── DescriptorInterface.php.bin
                                            │   ├── Descriptor.php.bin
                                            │   ├── JsonDescriptor.php.bin
                                            │   ├── MarkdownDescriptor.php.bin
                                            │   ├── TextDescriptor.php.bin
                                            │   └── XmlDescriptor.php.bin
                                            ├── Formatter
                                            │   ├── OutputFormatterInterface.php.bin
                                            │   ├── OutputFormatter.php.bin
                                            │   ├── OutputFormatterStyleInterface.php.bin
                                            │   ├── OutputFormatterStyle.php.bin
                                            │   └── OutputFormatterStyleStack.php.bin
                                            ├── Helper
                                            │   ├── DebugFormatterHelper.php.bin
                                            │   ├── DescriptorHelper.php.bin
                                            │   ├── DialogHelper.php.bin
                                            │   ├── FormatterHelper.php.bin
                                            │   ├── HelperInterface.php.bin
                                            │   ├── Helper.php.bin
                                            │   ├── HelperSet.php.bin
                                            │   ├── InputAwareHelper.php.bin
                                            │   ├── ProcessHelper.php.bin
                                            │   ├── ProgressHelper.php.bin
                                            │   ├── QuestionHelper.php.bin
                                            │   ├── TableHelper.php.bin
                                            │   ├── Table.php.bin
                                            │   └── TableStyle.php.bin
                                            ├── Input
                                            │   ├── ArgvInput.php.bin
                                            │   ├── ArrayInput.php.bin
                                            │   ├── InputArgument.php.bin
                                            │   ├── InputAwareInterface.php.bin
                                            │   ├── InputDefinition.php.bin
                                            │   ├── InputInterface.php.bin
                                            │   ├── InputOption.php.bin
                                            │   └── Input.php.bin
                                            └── Output
                                                ├── ConsoleOutputInterface.php.bin
                                                ├── ConsoleOutput.php.bin
                                                ├── NullOutput.php.bin
                                                ├── OutputInterface.php.bin
                                                ├── Output.php.bin
                                                └── StreamOutput.php.bin

32 directories, 87 files
]]></example>

<break lines="1" section="php7ast"/>
<blurb fontsize="1.1em" align="left">✔ Abstract Syntax Tree!!</blurb>

<example fontsize="1.1em" result='0' title=""><![CDATA[
<?php
echo substr("abc", [1,2]);
]]></example>

<example fontsize="0.8em" result='0' title="" type="shell nohighlight"><![CDATA[
% phan -a test.php
AST_STMT_LIST @ 1
    0: AST_STMT_LIST @ 2
        0: AST_ECHO @ 2
            0: AST_CALL @ 2
                0: AST_NAME @ 2
                    flags: NAME_NOT_FQ (1)
                    0: "substr"
                1: AST_ARG_LIST @ 2
                    0: "abc"
                    1: AST_ARRAY @ 2
                        0: AST_ARRAY_ELEM @ 2
                            flags: 0
                            0: 1
                            1: null
                        1: AST_ARRAY_ELEM @ 2
                            flags: 0
                            0: 2
                            1: null
]]></example>
<example fontsize="0.8em" result='0' title="" type="shell nohighlight"><![CDATA[
% phan -a test.php
test.php:2 TypeError arg#2(start) is int[] but substr() takes int
]]></example>

<break lines="1" section="php7ret"/>
<blurb fontsize="1.1em" align="left">✔ Return Types</blurb>
<example fontsize="1.1em" result='0' title=""><![CDATA[
<?php
function get_config(): array {
    return 42;
}
get_config();

// Catchable fatal error: Return value of get_config() must
//  be of the type array, integer returned in %s on line %d
]]></example>
<break lines="1" section="php7STH"/>

<blurb fontsize="1.1em" align="left">✔ Coercive Scalar Types</blurb>

<example fontsize="1.1em" result='0' title=""><![CDATA[
<?php
function logmsg(string $msg, int $level, float $severity) {
    var_dump($msg);      // string(1) "1"
    var_dump($level);    // int(2)
    var_dump($severity); // float(3)
}
logmsg(1, "2.5", 3);
]]></example>
<blurb fontsize="1.1em" align="left">✔ Strict Scalar Types</blurb>
<example fontsize="1.1em" result='0' title=""><![CDATA[
<?php
declare(strict_types=1);

logmsg(1, "2.5", 3);
]]></example>
<example fontsize="1.1em" result='0' title=""><![CDATA[
Fatal error: Argument 1 passed to logmsg() must be of the 
type string, integer given
]]></example>

<break lines="1" section="php7anon"/>
<blurb fontsize="1.1em" align="left">✔ Anonymous Classes</blurb>
<example fontsize="1.2em" result='0' title=""><![CDATA[
<?php
return new class($controller) implements Page {
    public function __construct($controller) {
        /* ... */
    }
    /* ... */
};

class MyObject extends MyStuff {
    public function getInterface() {
        return new class implements MyInterface {
            /* ... */
        };
    }
}
]]></example>

<break lines="1" section="php7coalesce"/>
<blurb fontsize="1.1em" align="left">✔ Null Coalesce Operator</blurb>
<example fontsize="1.5em" result='0' title=""><![CDATA[
<?php
$a = NULL;
$b = 1;
$c = 2;

echo $a ?? $b; // 1
echo $c ?? $b; // 2
echo $a ?? $b ?? $c; // 1
echo $a ?? $x ?? $c; // 2
]]></example>

<break lines="1" section="Spaceship"/>
<blurb fontsize="1.1em" align="left">✔ Spaceship Operator</blurb>
<example fontsize="1.5em" result='0' title=""><![CDATA[
|=|  Tie Fighter
k=k  Tie Interceptor
<==> Tie Bomber  
<=>  Tie Advanced X1 ✔ 
]]></example>
<example fontsize="1.1em" result='0' title=""><![CDATA[
<?php

function cmp_php5($a, $b) {
    return ($a < $b) ? -1 : (($a >$b) ? 1 : 0);
}

function cmp_php7($a, $b) {
    return $a <=> $b;
}
]]></example>

<break lines="1" section="php7excep"/>
<blurb fontsize="1.1em" align="left">✔ Exceptions on Fatals</blurb>
<example fontsize="1.1em" result='0' title=""><![CDATA[
<?php
function call_method($obj) {
    $obj->method();
}

call_method(null);
// Fatal error: Call to a member function method() on a non-object
]]></example>

<example fontsize="1.1em" result='0' title=""><![CDATA[
<?php
try {
    call_method(null);
} catch (EngineException $e) {
    echo "Exception: {$e->getMessage()}\n";
}
// Exception: Call to a member function method() on a non-object
]]></example>

<break lines="1" section="php7closecall"/>
<blurb fontsize="1.1em" align="left">✔ Added Closure::call()</blurb>
<example fontsize="1.1em" result='0' title=""><![CDATA[
<?php
$f = function () {
    return $this->n;
};
class MyClass {
    private $n = 42;
}
$myC = new MyClass;
$c = $f->bindTo($myC, "MyClass");
$c();
]]></example>

<example fontsize="1.1em" result='0' title=""><![CDATA[
<?php
$f = function () {
    return $this->n;
};
class MyClass {
    private $n = 42;
}
$myC = new MyClass;
$f->call($myC);
]]></example>

<break lines="1" section="php7cleanups"/>
<blurb fontsize="1.1em" align="left">✔ Removal of many deprecated featuresBR/
     (Your PHP4 code will break!)</blurb>
<example result='0' title=""><![CDATA[
- ext/ereg (use ext/pcre instead)
- preg_replace() eval modifier (use preg_replace_callback() instead)
- ext/mysql (use ext/mysqli or ext/pdo_mysql instead)
- Assignment of new by reference
- Scoped calls of non-static methods from incompatible $this context

- dl() in php-fpm
- set_magic_quotes_runtime() and magic_quotes_runtime()
- set_socket_blocking() (use stream_set_blocking() instead)
- mcrypt_generic_end() (use mcrypt_generic_deinit() instead)
- mcrypt_ecb, mcrypt_cbc, mcrypt_cfb and mcrypt_ofb 
  (use mcrypt_encrypt() and mcrypt_decrypt() instead)
- datefmt_set_timezone_id() and IntlDateFormatter::setTimeZoneID() 
  (use datefmt_set_timezone() or IntlDateFormatter::setTimeZone() instead)

- xsl.security_prefs (use XsltProcessor::setSecurityPrefs() instead)
- iconv.input_encoding, iconv.output_encoding, iconv.internal_encoding,
  mbstring.http_input, mbstring.http_output and mbstring.internal_encoding
  (use php.input_encoding, php.internal_encoding and php.output_encoding instead)

- $is_dst parameter of the mktime() and gmmktime() functions
- # style comments in ini files (use ; style comments instead)
- String category names in setlocale() (use LC_* constants instead)
- Unsafe curl file uploads (use CurlFile instead)
- PDO::PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT driver option 
  (use PDO::ATTR_EMULATE_PREPARES instead)
- CN_match and SNI_server_name stream context option (use peer_name instead)
]]></example>


<break lines="1" section="php7reserved"/>
<blurb fontsize="1.1em" align="left">✔ New reserved words:</blurb>
<list>
<bullet fontsize="1em" type="none">bool</bullet>
<bullet fontsize="1em" type="none">int</bullet>
<bullet fontsize="1em" type="none">float</bullet>
<bullet fontsize="1em" type="none">string</bullet>
<bullet fontsize="1em" type="none">null</bullet>
<bullet fontsize="1em" type="none">false</bullet>
<bullet fontsize="1em" type="none">true</bullet>
<bullet fontsize="1em" type="none">resource</bullet>
<bullet fontsize="1em" type="none">object</bullet>
<bullet fontsize="1em" type="none">mixed</bullet>
<bullet fontsize="1em" type="none">numeric</bullet>
</list>

<break lines="1" section="php7num"/>

<blurb fontsize="1.1em" align="left">✔ 64-bit integer support on Windows</blurb>
<blurb fontsize="1.1em" align="left">✔ Cleanup edge-case integer overflow/underflow</blurb>
<blurb fontsize="1.1em" align="left">✔ Support for strings with length >= 2^31 bytes in 64 bit builds.</blurb>
<blurb fontsize="1.1em" align="left">✔ Parse error on invalid numeric literals</blurb>
<example result='0' title=""><![CDATA[
<?php
$mask = 0855;  // Parse error: Invalid numeric literal
]]></example>

<break lines="1" section="php7UVS"/>

<blurb fontsize="1.1em" align="left">✔ Uniform variable syntax</blurb>

<example result='0' title=""><![CDATA[
<?php
// left-to-right
$this->$belongs_to['column']
// vs.
$this->{$belongs_to['column']}

// support missing combinations of operations
$foo()['bar']()
[$obj1, $obj2][0]->prop
getStr(){0}
 
// support nested ::
$foo['bar']::$baz
$foo::$bar::$baz
$foo->bar()::baz()
 
// support nested ()
foo()()
$foo->bar()()
Foo::bar()()
$foo()()
 
// support operations on arbitrary (...) expressions
(...)['foo']
(...)->foo
(...)->foo()
(...)::$foo
(...)::foo()
(...)()
 
// two more practical examples for the last point
(function() { ... })()
($obj->closure)()
 
// support all operations on dereferencable scalars
// (not very useful)
"string"->toLower()
[$obj, 'method']()
'Foo'::$bar
]]></example>

<break lines="1" section="php7phanbc"/>

<example fontsize="1em" result='0' title=""><![CDATA[
  echo preg_replace('/:-:(.*?):-:/e', '$this->pres->\\1', $text);
]]></example>
<example fontsize="1em" result='0' title=""><![CDATA[
  echo preg_replace_callback(
    '/:-:(.*?):-:/', 
    function($matches) {
      return $this->pres->$matches[1]; // Oops!
    },
    $text);
]]></example>

<example fontsize="0.8em" result='0' title="" type="shell nohighlight"><![CDATA[
% phan -b display.php
Files scanned: 1
Time:		0.13s
Classes:	8
Methods:	55
Functions:	5
Closures:	5
Traits:		0
Conditionals:	307
Issues found:	1

display.php:416 CompatError expression may not be PHP 7 compatible
]]></example>

<example fontsize="1em" result='0' title=""><![CDATA[
  echo preg_replace_callback(
    '/:-:(.*?):-:/', 
    function($matches) {
      return $this->pres->{$matches[1]}; // Ok
    },
    $text);
]]></example>

<break lines="1" section="php7unicode"/>

<blurb fontsize="1.1em" align="left">✔  Unicode Codepoint Escape Syntax</blurb>
<example fontsize="1.2em" result='1' title=""><![CDATA[
<?php
echo "\u{202E}Right-to-left text";

echo "\u{1F602}";
]]></example>

<blurb fontsize="1.1em" align="left">✔ ICU IntlChar class added to intl extension</blurb>


<break lines="1" section="php7more"/>

<blurb fontsize="1.5em">GA release scheduled for November 2015</blurb>

</slide>
