Skip to content

Instantly share code, notes, and snippets.

@alphaolomi
Created January 19, 2023 08:27
Show Gist options
  • Save alphaolomi/48eb220f12e43dd4250c6ec1e1049095 to your computer and use it in GitHub Desktop.
Save alphaolomi/48eb220f12e43dd4250c6ec1e1049095 to your computer and use it in GitHub Desktop.
Don't Try this
<?php
// https://twitter.com/timacdonald87/status/1615918480976662529/photo/1
class Foo
{
static function bar()
{
return Bar::class;
}
}
class Bar
{
static $bar = Baz::class;
}
class Baz
{
const qux = Qux::class;
}
class Qux
{
public static function quuz()
{
return Quuz::class;
}
}
echo Foo::bar()::$bar::qux::quuz();
// Quuz%
// Notes: It doesn't actually execute the final class,
// it just reads it as a string as it's `ClassName::class`.
<?php
// https://www.php.net/manual/en/language.references.return.php
// https://twitter.com/timacdonald87/status/1615886928943153153
class MyList{
private $list = [];
function &getList(){
return $this->list;
}
function add($item){
$this->list[] = $item;
}
}
$list = new MyList();
$list->add(1);
$list->add(2);
$arr = &$list->getList();
$arr[] = 3;
$arr[] = 4;
print_r($list->getList());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment