Skip to content

Instantly share code, notes, and snippets.

@dimabory
Last active January 30, 2019 10:23
Show Gist options
  • Save dimabory/3351f9a2b21fcd8f7e8f204a8e134018 to your computer and use it in GitHub Desktop.
Save dimabory/3351f9a2b21fcd8f7e8f204a8e134018 to your computer and use it in GitHub Desktop.
return true
<?php
function foo($x)
{
return $x === $x();
}
<?php
class Bar {}
function foo(Bar $x)
{
return get_class($x) != 'Bar';
}
<?php
class Bar
{
private $a;
public function __construct($a)
{
$this->a = (bool) $a;
}
public function a()
{
return $this->a;
}
}
function foo(callable $x)
{
$object = new Bar(false);
$x($object);
return $object->a();
}
<?php
class Test
{
private $foo = true;
}
function foo($x)
{
$o = (array) new Test;
return $o[$x];
}
@dimabory
Copy link
Author

dimabory commented Jan 3, 2019

4

foo("\0Test\0foo")

read more how it works - http://ocramius.github.io/blog/fast-php-object-to-array-conversion

@dimabory
Copy link
Author

3

Closure::bind(function(Bar $obj) { $obj->a = true; }, null, 'Bar')

read more how it works - https://ocramius.github.io/blog/accessing-private-php-class-members-without-reflection/

@dimabory
Copy link
Author

2

foo(new class() extends Bar {})

@dimabory
Copy link
Author

1

foo($a = function() use (&$a) { return $a; })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment