메소드의 코드를 얻는 방법은 무엇입니까? 나는 이런 식으로 뭔가를 시도하고있다 :클래스의 메소드 코드를 얻는 방법
//SiteController.php
class SiteController{
public function actionIndex(){
//bla bla..
}
public function actionCustomMethod(){
if(1){
echo '1';
} else {
echo '2';
}
}
}
//i need take code of "function actionCustomMethod(){ ... }"
preg_match('/function actionCustomMethod[^}]+/i', file_get_contents('SiteController.php'), $out);
//but the preg_match returns
/*
public function actionCustomMethod(){
if(1){
echo '1';
*/
내가 중첩 된 중괄호와 코드를 얻을하는 방법을 모르겠어요. 어떤 아이디어?
정규 표현식은 중첩 된 데이터 구조를 비교하는 데 적합하지 않습니다. 간단한 파서를 작성해야합니다. – Barmar
[Reflection] (http://php.net/manual/en/book.reflection.php) –
고마워, 오늘 밤해볼 게. – user2629587