function main() { $a = new a(); $x = new x(); echo "Calling a->pub\n"; $a->pub(); echo "Calling x->pub\n"; $x->pub(); }
function y() { $this->privatep = 2; $this->privatepa[] = 3; self::$privatepsself = 4; static::$privatepsstatic = 5; }
function y2($property2, $property4, $property2y, $property4y) { self::$property2 = $property2; self::$property4 = $property4; self::$property2y = $property2y; self::$property4y = $property4y; }
function y() { $this->defined = 1; $this->undefinedButMagic = 2; $y->undefinedButNotInternal = 3; // static calls x::$y = 2; }
function y() { self::$staticPropertySelf = 6; static::$staticPropertyStatic = 7; x::$staticPropertyx = 8; \x::$staticPropertyxFNS = 9; \otherClass::$staticPropertyxFNS = 10; parent::$staticPropertySelf = 11; }
public static function go() { self::$k = new y(); for ($i = 0; $i < 10; ++$i) { self::$set = $i; // enough to fool hphpc into leaving the // IssetS,EmptyS opcodes var_dump(empty(self::$set)); var_dump(isset(self::$set)); } }
function y() { // self::$staticPropertySelf = 6; static::$staticPropertyStatic = 7; parent::$staticPropertyParent = 11; x::$staticPropertyx = 8; \x::$staticPropertyxFNS = 9; w::$staticPropertyw = 8; \w::$staticPropertywFNS = 9; \otherClass::$staticPropertyxFNS = 10; }
function y() { // self::$staticPropertySelf = 6; static::$staticPropertyStatic = 7; // undeclared x::$staticPropertyx = 8; \x::$staticPropertyxFNS = 9; w::$staticPropertyx = 8; \w::$staticPropertyxFNS = 9; \otherClass::$staticPropertyxFNS = 10; }
function y() { echo x::e; echo \x::e; echo static::e; echo parent::e; echo x::$p; echo \x::$p; echo static::$p; echo parent::$p; echo x::method(); echo \x::method(); echo static::method(); echo parent::method(); }
function y() { self::$staticPropertySelf1 = 6; static::$staticPropertyStatic1 = 7; x::$staticPropertyx1 = 8; \x::$staticPropertyxFNS1 = 9; \otherClass::$staticPropertyxFNS1 = 10; parent::$staticPropertySelf1 = 11; self::$staticPropertySelf2 = 6; static::$staticPropertyStatic2 = 7; x::$staticPropertyx2 = 8; \x::$staticPropertyxFNS2 = 9; \otherClass::$staticPropertyxFNS2 = 10; parent::$staticPropertySelf2 = 11; self::$staticPropertySelf3 = 6; static::$staticPropertyStatic3 = 7; x::$staticPropertyx3 = 8; \x::$staticPropertyxFNS3 = 9; \otherClass::$staticPropertyxFNS3 = 10; parent::$staticPropertySelf3 = 11; }
<?php class x { function abc() { } static function sabc() { } } abC(); // dummy sabC(); // dummy new aBc(); // dummy new saBc(); // dummy $x->ABC(); $x->abc(); $x->sabC(); x::Sabc(); x::sabc();
<?php class x { function init() { $names = range('a', 'g'); foreach ($names as $n) { $this[$n]; } $this[] = 3; } } $X = new x(); $X->init(); print_r($X);
function y2($property2, $property4) { self::$property2 = $property2; self::$property4 = $property4; }
{ public function bf(); } interface c { public function cf(); } class x implements a, b, c { public function af() { echo 'af<br/>'; } public function aaf() { echo 'aaf<br/>'; } public function bf() { echo 'bf<br/>'; } public function cf() { echo 'cf<br/>'; } } $xy = new x(); $xy->af(); $xy->aaf(); $xy->bf(); $xy->cf();
<?php if (x::b('c', 3)) { $a = 1; }
public static function go() { self::$heh = array(); self::$heh->bar = 0; // we should know this can't affect $this->bar }
<?php function definedFunction() { } definedFunction(); undefinedFunction(); definedMethodUsedAsFunction(); $x->definedMethod(); x::definedStaticMethod(); class x { function definedMethod() { } static function definedStaticMethod() { } function definedMethodUsedAsFunction() { } }
/** * Parses a string by a set of available methods * * Available methods: * - json * - xml * - url * - query * - php * * @param string $string * @param string $mode * @return string */ static function parse($string, $mode = 'json') { if (is_array($string)) { return $string; } switch ($mode) { case 'json': $result = (array) @json_decode($string, true); break; case 'xml': $result = x::parse($string); break; case 'url': $result = (array) @parse_url($string); break; case 'query': if (url::has_query($string)) { $string = self::split($string, '?'); $string = a::last($string); } @parse_str($string, $result); break; case 'php': $result = @unserialize($string); break; default: $result = $string; break; } return $result; }
function y() { self::$usedInside = 3; }
<?php class x { static function define() { } } $X->define('a', 2); // can't be found x::define('b', 4); // can't be found $x::define('c', 6); // can't be found define('d', 7); // must be found
<?php class x { public $used = 1; public $uSed = 1; public $uSEd = 1; public $unused = 2; public $unUsed = 2; public $unUSed = 2; public $usedInside = 3; public $used_inside_various_cases = 3; public $used_INSIDE_various_cases = 3; public static $usedButStatic = 4; function y() { $this->usedInside = 3; $this->used_inside_various_cases = 5; $this->used_INSIDE_various_cases = 6; } } $x->used = 4; $x->uSed = 4; $x->uSEd = 4; $x->usedButStatic = 3; \x::$usedButStatic = 5;
<?php class x { static function y() { } } x::Y(); x::x(); X::y(); x::y();
function foo() { parent::bar(); parent::bar(); }
{ function usedMethod() { } function definedTwiceMethod() { } function unusedMethod() { } function methodNamedAsAFunction() { } function usedMethodNoCase() { } function usedMethodStatically() { } } class y { function definedTwiceMethod() { } } $y->usedMethod(); $yy->definedTwiceMethod(); $xxx->usedmethodnocase(); x::usedMethodStatically(); methodNamedAsAFunction();
<?php class x { public function abc() { print __METHOD__ . "\n"; } static function sabc() { print __METHOD__ . "\n"; } } $a = new x(); $a->abc(); // OK $a->sabc(); // Possible but weird x::abc(); // Should not be possible but actually is x::sabc(); // OK
<?php class x { static $staticReadWithSelf = array(1, 2, 3); static $staticReadWithStatic = array(1, 2, 4); static $staticModifiedWithSelf = array(1, 2, 5); static $staticModifiedWithStatic = array(1, 2, 6); static $staticModifiedWithThis = array(1, 2, 7); function y() { $a = self::$staticReadWithSelf; $b = static::$staticReadWithStatic; $a = self::$staticModifiedWithSelf++; static::$staticModifiedWithStatic[] = 1; $this->staticModifiedWithThis = 1; } } $z = new x(); $z->y(); print x::$staticModifiedWithThis;