Skip to content

Instantly share code, notes, and snippets.

@aaronpk
Created July 1, 2010 05:34
Show Gist options
  • Save aaronpk/459618 to your computer and use it in GitHub Desktop.
Save aaronpk/459618 to your computer and use it in GitHub Desktop.
Unexpected access to a protected object property in PHP
<?php
highlight_file(__FILE__);
echo '<hr />';
class A
{
protected $_x = 100;
public static function getX()
{
$a = new A();
return $a->_x;
}
}
class B
{
public static function getX()
{
$a = new A();
return $a->_x;
}
}
$a = A::getX();
var_dump($a);
$b = B::getX();
var_dump($b);
?>
@aaronpk
Copy link
Author

aaronpk commented Jul 1, 2010

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