Created
May 11, 2018 15:27
-
-
Save willitscale/99b3e9408311ee7cc9de024500cf3a48 to your computer and use it in GitHub Desktop.
PHP under the hood
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 | |
class MyClass { | |
function __invoke() | |
{ | |
echo 'invoked as a function', PHP_EOL; | |
} | |
} | |
$object = new MyClass; | |
$object(); |
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 | |
class NoToString { | |
} | |
$object = new NoToString; | |
// You can't cast a class to a string without toString | |
echo 'Without to string: ', var_export($object, true), PHP_EOL; | |
class WithToString { | |
function __toString() | |
{ | |
return 'MyString'; | |
} | |
} | |
$object = new WithToString; | |
echo 'With to string: ', $object, 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 | |
$object = (object) null; |
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 | |
$object = new stdClass; |
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 | |
class MyClass | |
{ | |
} | |
$object = new MyClass; |
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 | |
class MyClass { | |
function __construct() | |
{ | |
return; | |
} | |
} | |
$object = new MyClass; |
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
EXT_STMT Statement, a opcode which is commonly found between operations to enable debugger breakpoints | |
EXT_NOP No Operation, usually used for declaring a function or class | |
EXT_FCALL_BEGIN Function call begin, you've guessed it! It's the start of a function call | |
DO_FCALL Do Function call, execute the body of the function | |
EXT_FCALL_END Function call end, our function has finished | |
ASSIGN Assing a value | |
RETURN Either return a value from a function or executed at the end of the script | |
NEW Create a new object | |
CAST Cast one data type to another |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment