I need to parse my classes (which they are in separate files) and search for a specified variable or method, then if there was that variable so have to execute that.
我需要解析我的类(它们在单独的文件中)并搜索指定的变量或方法,然后如果有那个变量则必须执行它。
I tried some ways:
我试过一些方法:
-
I used to parse my files with preg_match seeking for some pattern.(not a good idea)
我曾经用preg_match解析我的文件寻找一些模式。(不是一个好主意)
-
after that I try some code parser extension that was not good enough.
之后我尝试了一些不够好的代码解析器扩展。
-
finally I tried
ArrayObject
class that it was not fine at all.(because it was parsing objects not classes)最后我尝试了ArrayObject类,它根本就不好。(因为它解析对象而不是类)
is there any way to do that?
有没有办法做到这一点?
Pseudo-code:
伪代码:
$file = file_get_content("dir/myClassFile.php");
$classname='foo';
if(there was '$variable=x' in $classname)
include "dir/myClassFile.php";
edit
编辑
file content:
文件内容:
class foo {
var include = true; //1st
function bar()
{
$this->include = true; //2nd
}
}
I need to check if include is ture then I have to include then file.
我需要检查包含是否真的然后我必须包括然后文件。
1 个解决方案
#1
1
For simple syntax checking, using php on the command line goes a long way. Simply call:
对于简单的语法检查,在命令行上使用php有很长的路要走。只需致电:
$ php -l <filename>
For more complex tools, check out Sebastian Bergmann's github. He is the author of phpunit, and has developed some really useful tools for detecting copy-pasted code, dead code, etc.
有关更复杂的工具,请查看Sebastian Bergmann的github。他是phpunit的作者,并开发了一些非常有用的工具来检测复制粘贴的代码,死代码等。
Github帐户
It would be a good idea to test your classes with PHPUnit, to make sure they function/work correctly.
使用PHPUnit测试您的类是一个好主意,以确保它们正常运行/工作。
There is also this PHP Code Sniffer that might come in use too.
这个PHP Code Sniffer也可能会被使用。
#1
1
For simple syntax checking, using php on the command line goes a long way. Simply call:
对于简单的语法检查,在命令行上使用php有很长的路要走。只需致电:
$ php -l <filename>
For more complex tools, check out Sebastian Bergmann's github. He is the author of phpunit, and has developed some really useful tools for detecting copy-pasted code, dead code, etc.
有关更复杂的工具,请查看Sebastian Bergmann的github。他是phpunit的作者,并开发了一些非常有用的工具来检测复制粘贴的代码,死代码等。
Github帐户
It would be a good idea to test your classes with PHPUnit, to make sure they function/work correctly.
使用PHPUnit测试您的类是一个好主意,以确保它们正常运行/工作。
There is also this PHP Code Sniffer that might come in use too.
这个PHP Code Sniffer也可能会被使用。