class A
{
function A()
{
echo "build A";
}
function __destruct()
{
echo "destroy A";
}
}
$obj = new A();
//unset($obj);
namespace Foo;
class Bar {
public function Bar() {
// treated as constructor in PHP 5.3.0-5.3.2
// treated as regular method as of PHP 5.3.3
}
}
function __construct()
{
echo "construct A";
}
function A()
{
echo "build A";
}
function __destruct()
{
echo "destroy A";
}
}
class MethodTest
{
public function __call($name, $arguments)
{
// Note: value of $name is case sensitive.
echo "Calling object method '$name' "
. implode(' ', $arguments). "<br>";
}
public static function __callStatic($name, $arguments)
{
// Note: value of $name is case sensitive.
echo "Calling static method '$name' "
. implode(' ', $arguments). "<br>";
}
}
$obj = new MethodTest;
$obj->runTest('in','object','context');
MethodTest::runTest('in','static','context');
class TestMagicCallMethod {
public function foo()
{
echo __METHOD__.PHP_EOL."<br>";
}
public function __call($method, $args)
{
echo __METHOD__.PHP_EOL."<br>";
if(method_exists($this, $method))
{
$this->$method();
}
}
protected function bar()
{
echo __METHOD__.PHP_EOL."<br>";
}
private function baz()
{
echo __METHOD__.PHP_EOL."<br>";
}
}
$test = new TestMagicCallMethod();
$test->foo();
/**
* Outputs:
* TestMagicCallMethod::foo
*/
$test->bar();
/**
* Outputs:
* TestMagicCallMethod::__call
* TestMagicCallMethod::bar
*/
$test->baz();
/**
* Outputs:
* TestMagicCallMethod::__call
* TestMagicCallMethod::baz
*/
class Test
{
public function __get($key)
{
echo $key . " not exists";
}
public function __set($key,$value)
{
echo $key . " = ".$value;
}
}
$t = new Test();
echo $t->name."<br>";
$t->name = "abc";
class Test
{
private $name = "abc";
private $age = 12;
public function __toString()
{
return "name : $this->name, age : $this->age";
}
}
$t = new Test();
echo $t;
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有