¡¡×i½uÔÚ¿´java±a³Ì˼Ïe£¬¿´µ½ÀaÐÍÐÅÏ¢ÕaÒ»Õ£¬½²µ½ÁËÀaµÄÐÅÏ¢ÒÔ¼°´ÉaµÄ¸ÅÄi¡£Ë³±aιÊÒ»ÏÂphpµÄ´Éa¶«Î÷¡£ÊÖ²aÊÇÕaÑu˵µÄ£º"PHP 5 ¾ßÓÐÍeÕuµÄ´Éa API£¬Ìi¼ÓÁ˶ÔÀa¡¢½Ó¿Ú¡¢º¯Êý¡¢½¨ºÍÀ(C)Õ¹½øÐдÏo¹¤³ÌµÄÄÜÁ¦¡£ ´ËÍa£¬´Éa API Ìa¹(C)Á˽¨À´È¡³oº¯Êý¡¢ÀaºÍ½¨ÖеÄÎĵµ×¢ÊÍ¡£"µ±È»ÊÖ²aÉÏ˵µÄÓÐÐ(C)³eÏo£¡ËuνµÄÄaeÏo˵°×¾ÍÊÇÄÜ»ñÈ¡¹ØÓÚÀa¡¢½*¨¡¢ÊoÐÔ¡¢²ÎÊýµÈµÄÏeϸÐÅÏ¢£¬°uÀ¨×¢ÊÍ! ÎÄ×Ö×ÜÊÇÄÇô¿ÝÔi£¬¾Ù¸oÀý×Ó
class Foo {
public $foo = 1;
protected $bar = 2;
private $baz = 3;
/**
* Enter description here ...
*/
public function myMethod()
{
echo 'hello 2b';
}
}
$ref = new ReflectionClass('Foo');
$props = $ref->getProperties();
foreach ($props as $value) {
echo $value->getName()."\n";
}
//output
//foo
//bar
//baz
ReflectionClass Õa¸oÀaµ»Øʱij¸oÀaµÄÏa¹ØµÄÐÅÏ¢£¬±ÈÈç ÊoÐÔ£¬½¨£¬ÃuÃu¿Õ¼a£¬ÊµÏÖÄÇÐ(C)½Ó¿ÚµÈ£¡ÉϸoÀý×ÓÖÐReflectionClass:: getProperties µ»ØÊÇ ReflectionProperty ¶ÔÏoµÄÊý×e¡£
ReflectionProperty Àa±¨¸aeÁËÀaµÄÊoÐÔµÄÏa¹ØÐÅÏ¢¡£±ÈÈç isDefault isPrivate isProtected isPublic isStaticµÈ£¬½¨getName ÊÇ»ñÈ¡ÊoÐÔµÄÃu³Æ£¡
ÒÔÉÏÊÇ»ñÈ¡ÊoÐԵģ¬»¹ÓлñÈ¡Àa½¨µÄ±ÈÈç
class Foo {
public $foo = 1;
protected $bar = 2;
private $baz = 3;
/**
* Enter description here ...
*/
public function myMethod()
{
echo 'hello 2b';
}
}
$ref = new ReflectionClass('Foo');
$method = $ref->getMethod('myMethod');
$method->invoke($ref->newInstance());
ReflectionClass::getMethod ÊÇ´ÊÇÒ»¸o ReflectionMethod ÀaÐÍ £¬ReflectionMethod Àa±¨¸aeÁËÒ»¸o½¨µÄÓйØÐÅÏ¢£¬±ÈÈç isAbstract isPrivate isProtected isPublic isStatic isConstructor£¬»¹ÓÐÒ»¸oÖØÒªµÄ½¨Invoke£¬InvokeArgs ¾ÍÊÇÖ´Ðн*¨£¡
ÆaËuµÄ¶ÔÏo¿ÉÒÔ¿´¿´ÊÖ²a£¬²»ÊǺÜÄÑ£¡
ÄÇ*´Éa¾¿¾¹ÓÐÄÄÐ(C)ÓÃ;£¿
´ÉaÊÇÒ»¸o¶¯Ì¬ÔËÐеĸÅÄi£¬×ÛºÏʹÓÃËuÃÇ¿ÉÓÃÀ´°iÖuÎÒÃÇÖÎoÆaËuÀa£¬½Ó¿Ú£¬½¨£¬ÊoÐÔ£¬½¨ºÍÀ(C)Õ¹¡£»¹¿É¹¹½¨Ä£Ê½£¬±ÈÈ綯̬´uÀi¡£ÔÚÒ»Ð(C)php¿o¼ÜÖÐʹÓôÉaÒ²ÊǺܾ³££¬±ÈÈçkohana£¬yii£¬ÏÂÃaeÊÇkohana µÄʵÏÖmvcµÄ´uÂe£¬¾ÍÊÇÓõ½ÁË´Éa£¡
// Start validation of the controller
$class = new ReflectionClass(ucfirst(Router::$controller).'_Controller');
// Create a new controller instance
$controller = $class->newInstance();
// Load the controller method
$method = $class->getMethod(Router::$method);
// Execute the controller method
$method->invokeArgs($controller, $arguments);
ÉÏÃaeµÄ´uÂe¿ÉÒÔÇaÎu¿´µ½Õa¸o¿o¼ÜµÄÁ÷³Ì£¡Í¨¹ýRouter Æaʵ¾Í´¦ÀiurlµÄÀa£¬Í¨¹ýRouter¿ÉÒÔ»ñÈ¡Äĸo¿ØÖÆÆ÷¡¢Äĸo½¨£¡È»ºoÔÙÖ´Ðн¨£¡
ÒÔÉϾÍÊǶÔPHP *´ÉaµÄ×ÊÁÏÕuÀi£¬ºoÐø¼ÌÐø²¹³aÏa¹Ø×ÊÁÏ£¬Ð»Ð»´o¼Ò¶Ô±¾Õ¾µÄÖ§³Ö£¡