This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function xrange( $start, $limit, $step = 1 ) { | |
for ( $i = $start; $i <= $limit; $i += $step ) { | |
yield $i; | |
} | |
} | |
/* | |
* An array is never created or returned |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace wctrn\realloc; | |
trait Logger { | |
public function log_error( string $msg ) : bool { | |
return error_log( $msg ); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
try { | |
// Something throws an Exception or Error. | |
} catch ( Throwable $t ) { | |
// will match only in PHP 7 | |
} catch ( Exception $e ) { | |
// will be reached in PHP 5 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace wctrn\realloc; | |
require_once 'late-static-bindings-post.php'; | |
class Page extends Post { | |
public function get_content() { | |
return 'Hello Turin!'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace wctrn\realloc; | |
class Post { | |
public static function init() { | |
return new static(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace wctrn\realloc; | |
class Post { | |
protected $content; | |
public function get_content() : string { | |
return $this->content; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace wctrn\realloc; | |
class Post { | |
protected $content; | |
public function set_content( string $content ) { | |
$this->content = $content; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once 'namespace-class.php'; | |
// Namespace: Using | |
echo ( new \wctrn\realloc\Post() )->get_content(), PHP_EOL; | |
// Namespaces: Importing | |
use \wctrn\realloc\Post; | |
echo ( new Post() )->get_content(), PHP_EOL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace wctrn\realloc; | |
class Post { | |
public function get_content() { | |
return 'Hello World!'; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
abstract class aFoo { | |
abstract function baz( int $foobar ); | |
} | |
abstract class aBar extends aFoo { | |
// expected type of foobar is still int | |
abstract function baz( $foobar ) : int; | |
} |