Skip to content

Instantly share code, notes, and snippets.

@willitscale
Created May 11, 2018 15:27
Show Gist options
  • Save willitscale/99b3e9408311ee7cc9de024500cf3a48 to your computer and use it in GitHub Desktop.
Save willitscale/99b3e9408311ee7cc9de024500cf3a48 to your computer and use it in GitHub Desktop.
PHP under the hood
<?php
class MyClass {
function __invoke()
{
echo 'invoked as a function', PHP_EOL;
}
}
$object = new MyClass;
$object();
<?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;
<?php
$object = (object) null;
<?php
$object = new stdClass;
<?php
class MyClass
{
}
$object = new MyClass;
<?php
class MyClass {
function __construct()
{
return;
}
}
$object = new MyClass;
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