Last active
January 30, 2019 10:23
-
-
Save dimabory/3351f9a2b21fcd8f7e8f204a8e134018 to your computer and use it in GitHub Desktop.
return true
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 foo($x) | |
{ | |
return $x === $x(); | |
} |
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 Bar {} | |
function foo(Bar $x) | |
{ | |
return get_class($x) != 'Bar'; | |
} |
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 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(); | |
} |
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 Test | |
{ | |
private $foo = true; | |
} | |
function foo($x) | |
{ | |
$o = (array) new Test; | |
return $o[$x]; | |
} |
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/
2
✅ foo(new class() extends Bar {})
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
4
✅
foo("\0Test\0foo")
read more how it works - http://ocramius.github.io/blog/fast-php-object-to-array-conversion