开发者

PHP : Can I compile/build my site like .NET?

开发者 https://www.devze.com 2023-02-23 05:08 出处:网络
I am new to PHP, and working on a class based web site. So my question is simple. Can I compile the site like I can in .NET?

I am new to PHP, and working on a class based web site. So my question is simple. Can I compile the site like I can in .NET?

This would be helpful to me because I changed my IsAAction interface to accept an error callback function as a parameter of the Execute function, and I wo开发者_StackOverflow中文版uld like all of my implementations to break so I can easily see where to change them.

Thanks in advance.


PHP can be compiled, as in you can compile it to machine code and prevent a parsing everytime you access a file. That the way accelerator like APC work. But you can't compile it like a .NET DLL with every error checked in advance. It would go against its dynamic nature. Late binding mean it will always check for error at runtime

For your particuliar problem, I would suggest adding Unit Tests to your project. They are very good to have anyway, and they will help you catch error in your interface implementation. I personally couldn't live without them. You may want to check PHPUnit or SimpleTests.

EDIT To understand why PHP can't check your error, just check this snippet of code.

if ($_GET['impl'] == 'interface1') {
    interface MyInterface {
        function foo($var);
    }
} else {
    interface MyInterface {
        function bar($var, $var2);
    }
}

class Implementation implements MyInterface { //Will crash or not depending on the URL!
    function foo($var) {}
}


Yes and no. See:

Can you "compile" PHP code?

And:

http://www.phpcompiler.org/

And:

http://www.scriptol.com/apollo.php


https://github.com/facebook/hiphop-php/wiki - although I'm sure there are other answers on here that you'd find useful.


There's a opened topic on stackoverflow that is related.

Can you “compile” PHP code?

Some parties such as Facebook rewrote PHP runtime, or part of it so they make it possible to run compiled php code or other source codes, pretty much whatever you like.

HipHop for PHP

Its not an easy task. But you can do it.


Not to my knowledge. PHP is a script language.

0

精彩评论

暂无评论...
验证码 换一张
取 消