function test() { $a = X::foo(); $a(); $a = Y::foo(); $a(); $a = X::bar(); $a(); $a = Y::bar(); $a(); $x = new X(); $a = $x->bar(); $a(); $x = new Y(); $a = $x->bar(); $a(); $a = X::bar_nonstatic(); $a(); $a = Y::bar_nonstatic(); $a(); $x = new X(); $a = $x->bar_nonstatic(); $a(); $x = new Y(); $a = $x->bar_nonstatic(); $a(); }
function test() { $x = new X(); $y = new Y(); $x->f(); $y->f(); }
function test($a) { $x = new X(); while (true) { $x->foo(new Exception()); } }
function test() { $x = new X(); $c = $x->f(); var_dump($c(true)); $y = new Y(); $c = $y->f(); var_dump($c("foo")); }
function test() { $x = new X(); $x->set(); $s = serialize($x); $y = unserialize($s); $y->foo(); var_dump($y); }
function test() { $x = new X(); $f = $x->gen(function ($x) { var_dump(get_class($x)); }); foreach ($f() as $e) { var_dump($e); } }
protected function createToken($expired = false) { $s = new Auth\Schema\Sessions(X::DB()); $token = md5(uniqid('', true)); X::DB()->insert($s->getTable())->set('token', $token)->set('user_id', 1)->set('ip', ip2long('127.0.0.1'))->set('expires_at', date('Y-m-d H:i', strtotime($expired ? '-1 day' : '+1 day')))->execute(); return $token; }
function test($str) { X::bar($str); (new X())->bar($str); Y::bar($str); (new Y())->bar($str); }
function test() { $x = new X(); var_dump($x->foo()->bar); var_dump($x->foo()->bar); var_dump($x->foo()->bar); var_dump(foo()->bar); foo()->bar = 6; var_dump(foo()->bar); foo()->bar = 7; var_dump(foo()->bar); foo()->bar = 8; var_dump(foo()->bar); bar()->bar = 6; var_dump(bar()->bar); bar()->bar = 7; var_dump(bar()->bar); bar()->bar = 8; var_dump(bar()->bar); }
function foo($x) { global $f; if ($x == 0) { echo "statically known invoke\n"; $g = function ($x) { var_dump(__METHOD__); }; $g::__invoke(f()); } else { if ($x == 1) { echo "call_user_func\n"; call_user_func(array(get_class($f), "__invoke"), f()); } else { echo "X::bar\n"; X::bar(); echo "cuf(X::bar)\n"; call_user_func(array('X', 'bar')); echo "statically unknown invoke\n"; $f::__invoke(f()); } } }
<?php const X = 1; class X { function f() { if (isset(X[$a])) { } if (isset(Y::X[$b])) { } if (isset(Y::$x[$b])) { } } } $x = new X(); $x->f();
<?php X::test(); /** Class X is related to neither ParentClass nor ChildClass. */ class X { public static function test() { $myChild = new ChildClass(); $myChild->secret(); // bug - invokes X::secret() instead of ChildClass::secret() } private function secret() { echo "Called private " . __METHOD__ . "() on an instance of: " . get_class($this) . "\n"; } } class ParentClass { private function secret() { } } class ChildClass extends ParentClass { public function secret() { echo "Called public " . __METHOD__ . "() on an instance of: " . get_class($this) . "\n"; } }
<?php class X { public function y() { echo "y\n"; return $this; } public function z() { echo "z\n"; return $this; } public function a($n) { return $n; } } $x = new X(); echo $x->y()->z()->a(1);
<?php class x { static function y() { } } x::Y(); x::x(); X::y(); x::y();
<?php class X { public function foo($y) { call_user_func(array($y, 'foo')); $y::foo(); } } class Y { public static function foo() { var_dump(__METHOD__); static::bar(); } public static function bar() { var_dump(__METHOD__); } } $x = new X(); $x->foo('y'); $x->foo(new Y());
/** * Менеджер подключения к БД * * @return DB */ function getManager() { return \X::DB(); }
public function print_choice($i, $v) { echo X::tr(array('onclick' => 'check_this_row(this)'), X::td(X::input(array('type' => 'checkbox', 'name' => "info[{$i}][check]", 'value' => $i, 'id' => 'check-' . (int) $v['infix'], 'onclick' => 'event.stopPropagation()'))), X::td($v['desc'], X::input(array('type' => 'hidden', 'name' => "info[{$i}][url]", 'value' => $v['url'])), X::input(array('type' => 'hidden', 'name' => "info[{$i}][desc]", 'value' => $v['desc']))), X::td(X::input(array('class' => 'span1', 'type' => 'text', 'name' => "info[{$i}][infix]", 'value' => $v['infix'], 'onclick' => 'event.stopPropagation()')))); }
echo "Accessing X from D:\n"; var_dump(get_class_methods("X")); } } class X { private function privX() { } protected function protX() { } public function pubX() { } public static function testFromX() { echo "Accessing C from X:\n"; var_dump(get_class_methods("C")); echo "Accessing D from X:\n"; var_dump(get_class_methods("D")); echo "Accessing X from X:\n"; var_dump(get_class_methods("X")); } } echo "Accessing D from global scope:\n"; var_dump(get_class_methods("D")); C::testFromC(); D::testFromD(); X::testFromX(); echo "Done";
function main(X $y) { $asd = 'asd'; return $y->go($asd); }
private function __file_get_contents($args) { if (!isset($args['$file'])) { return ''; } $fs = X::model('filesystem'); $domain = substr($this->url, 0, strpos($this->url, '/')); $domain_path = $fs->path($domain); $path = $fs->path(dirname($this->url)); $file = realpath($path['absolute'] . '/' . ltrim($args['$file'], '/')); $return = ''; //TODO: remove realpath checks if ($file && strpos($file, realpath($domain_path['absolute'])) === 0) { $return = file_get_contents($file); if (isset($args['$html_safe']) && $args['$html_safe']) { $return = htmlspecialchars($return); } if (isset($args['$nl2br']) && $args['$nl2br']) { $return = nl2br($return); } if (isset($args['$space2nbsp'])) { $return = str_replace(' ', ' ', $return); } } return $return; }
[expect] 1 [file] <?php if ($a == $b) { class X { static function f($a) { echo 1; } } } X::f(1);
<?php class X { static function g() { } } echo 'abc' . X::g() . 'efg';
<?php class X { static $y = array(); function z() { self::$y[] = 2; return self::$y; } } var_dump(X::z()); var_dump(X::z());
public static final function isX() { if (!isset(X::$x)) { X::$x = true; } return X::$x ? 1 : 0; }
*/ ext_func(); new ExtClass(); class L implements ExtInterface { } function f() { } function () { // Anonymous function. }; g(); $g(); ${$g}(); X::f(); call_user_func(); call_user_func('h'); call_user_func($var); class A { } class C extends B { } class D extends C { } new U(); V::m(); W::$n;
final class X { public static function getVal($val) { $ym = self::getArr($val); return self::get($ym[0]); } private static function check($val) { if (!is_int($val)) { throw new Exception(); } } private static function get($a) { return $a; } private static function getArr($val) { self::check($val); return array((int) $val); } } for ($i = 0; $i < 10; $i++) { try { var_dump(X::getVal("42")); } catch (Exception $e) { } } var_dump('done');
/** * Debug * ------------------------- **/ public function Debug($VAL) { if ($this->Debug) { X::Debug($VAL); } return true; }
<?php class X { function foo($x, $y) { $a = null; if ($x) { $a = new X(); } new X($y ? null : $a); return $a; } } $x = new X(); var_dump($x->foo(false, true));
<?php function __autoload($x) { var_dump('AUTOLOAD:' . $x); } class X { public $foo = Y::FOO; function foo() { var_dump(__METHOD__, $this); } } X::foo();
<?php function f() { throw new Exception('foo'); } class X { function foo() { try { f(); } catch (Exception $this) { return $this; } } } $x = new X(); $ex = $x->foo(); var_dump($ex->getMessage());