Skip to content

Instantly share code, notes, and snippets.



Created Mar 4, 2010
What would you like to do?
PHP zval experiments
final class v6_Variable{
private $val;
public function set($val){
$this->val = $val;
public function get(){
return $this->val;
final class v6_Zval{
private function __construct(){}
public static function getZvalDump($a){
$sc = new v6_Variable();
ob_start(array($sc, 'set'));
return $sc->get();
public static function isIdentical($a, $b){
$bd1 = self::getZvalDump($b);
$aref = $a;
$bd2 = self::getZvalDump($b);
return $bd1 !== $bd2;
function testIdentity($a, $b, $expected, $comment=''){
echo $comment.' should be '.var_export($expected, true).': ';
if(v6_Zval::isIdentical($a, $b) === $expected){
echo 'OK';
echo 'ERROR!';
$a = 1;
$b = 1;
testIdentity($a, $b, false, '');
testIdentity($b, $a, false, '');
$a = $b;
testIdentity($a, $b, true, '');
testIdentity($b, $a, true, '');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment