PHP元编程

1

<?php
class _Meta_Base {
		function __call($method, $arg_array) {
				echo $method . "<br />";
		}

		function doCallable() {
				$this->doCallBefore();
				$this->doCaller();
				$this->doCallAfter();
		}
}

class MetaClass extends _Meta_Base {
	function doSomething() {
		echo parent::doSomething();
	}

	function doCaller() {
			echo "A good solution for PHP meta programming<br />";
	}
}

$mc = new MetaClass();

$mc->doSomething();
$mc->doNothing();
$mc->doCallable();
?>

2

执行结果

$ php meta-test.php
doSomething
doNothing
doCallBefore
A good solution for PHP meta programming
doCallAfter
打赏

《PHP元编程》有一个想法

发表评论

电子邮件地址不会被公开。 必填项已用*标注