function foo() { parent::inAA(); parent::inA(); parent::inB(); parent::inTrait(); parent::nowhere(); c::inC(); }
public static function f0($a1) { AA::f1($a1); }
<?php /** * Created by PhpStorm. * User: USER * Date: 26/5/2015 * Time: 3:48 */ class AA { private static function fnPrivate($a, $b) { echo "ok to call a private static fn of an object. \$a=[{$a}] \$b=[{$b}]\n"; } public static function fnPublic($a, $b) { echo "ok to call a public static fn of an object. \$a=[{$a}] \$b=[{$b}]\n"; } public static function call_static_meth($nm, ...$prmAy) { call_user_func_array("AA::{$nm}", $prmAy); } } AA::call_static_meth("fnPublic", "aa", "bb"); AA::call_static_meth("fnPrivate", "aa", "bb"); call_user_func("AA::fnPublic", "aa", "bb"); // call_user_func("AA::fnPrivate");
<?php function __autoload($className) { try { include $className . ".php"; echo "<<<{$className}"; } catch (Exception $e) { echo "abc"; throw new Exception("need {$className}"); } } $a = new AA(); $a->test(); try { $a = new AA(); } catch (Exception $e) { echo $e->getMessage(); echo "\n************************\n"; } echo "\n&&&&&&&&&&&&&&&&&&&&&&&&&&&&\n"; class TestPrivate { private function say() { echo "private function say"; } public function run(TestPrivate $a) { $a->say(); }
{ $this->container = array("one" => 1, "two" => 2, "three" => 3); } public function offsetSet($offset, $value) { if (is_null($offset)) { $this->container[] = $value; } else { $this->container[$offset] = $value; } } public function offsetExists($offset) { return isset($this->container[$offset]); } public function offsetUnset($offset) { unset($this->container[$offset]); } public function offsetGet($offset) { if (!isset($this->container[$offset])) { throw new OutOfBoundsException("The offset '{$offset}' is out of bounds"); } return $this->container[$offset]; } } $a = new AA(); $val = $a->offsetGet("three"); //$val = $a->offsetGet(3); var_dump($val);
public static function f0() { if (AA::f1()) { echo "aa1 != 0\n"; } }
<?php class AA { public $a; private $b; protected $c; public function test() { $this->c = 10; return $this->c; } } $aa = new AA(); //$aa->c =10; //Fatal error: Cannot access protected property AA::$c //$aa->b = 12; //Fatal error: Cannot access private property AA::$b //echo $aa->c; //Fatal error: Cannot access protected property AA::$c echo $aa->test();