| 
| No PHP Compile Errors in eclipse PDT [message #65970] | Wed, 13 February 2008 08:17  |  | 
| Eclipse User  |  |  |  |  | Im using eclipse PDT for my PHP development because Im familiar with the eclipse IDE during my previous projects as a J2EE developer (RAD6 / IBM
 Websphere).
 
 One thing I really miss in PHP / Eclipse PDT compared to Java / Eclipse is
 the check for compilation errors.
 
 Example: I have a class Tax with a public method calculateTax() and this
 class is used in various other classes in my project.
 If I change the methodname caculateTax() of class Tax to calculateTaxes()
 or change the modifier from public to private the it doesnt cause any PHP
 compile errors in the classes using the Tax class. Only at runtime I will
 get a Call to undefined method Tax::calculateTax() in Tax on line xxx.
 Changing the method name or the modifer in a java class will cause compile
 errors in all java sourcecode using that class. Is it that Java is
 compiled and PHP isnt ?
 
 Eclipse PDT has code assist capabilities for PHP and I use it every day.
 If Code assist is working, it looks to me that it is only a small step to
 produce PHP compile errors in eclipse PDT.
 
 Does anybody know if  there are PHP compiler plugins for eclipse PDT? Are
 there other ways to generate PHP compile errors? I think this will be a
 huge improvement and will speed up development of PHP projects.
 
 Thanks.
 |  |  |  | 
|  | 
| 
| Re: No PHP Compile Errors in eclipse PDT [message #66054 is a reply to message #66012] | Wed, 13 February 2008 10:45   |  | 
| Eclipse User  |  |  |  |  | Mike Lubbers wrote: > How can we get syntax- or compile- errors on non-existing methods
 > instead of 'Fatal error: Call to undefined method...' during runtime?
 
 
 Hi Mike,
 
 
 I think there are two problems:
 
 First, the interpreter of the code can not always exactly know what kind
 of object you're talking to, except in those situations where the code
 is obvious. This is due to PHP's weak typed nature.
 
 Example:
 Let's say you have a factory implementation for whatever. You know the
 factory returns an object of a generic type, but you don't know the
 exact instance type.
 
 
 class Base { function b() {} }
 class A extends Base { function x () {} }
 class B extends Base { funciton y () {} }
 
 /**
 * @return Base an object
 */
 function factory ( $whatever ) {
 switch ( $whatever ) {
 case 'a': return new A ();
 case 'b': return new B ();
 }
 throw new Exception ( 'error!' );
 }
 
 $obj = factory ( 'a' );
 
 Here we see the problem, the type of $obj can not be known by the
 interpreter without actually running the file, since the type is defined
 at runtime.
 
 To make it even worse, we could also do:
 
 try {
 $obj = factory ( $_GET['someParam'] );
 } catch ( Exception $e ) {
 }
 
 And there is definitely no way the interpreter knows what type $obj is.
 So how should the IDE know if $obj has a method x() or a method y()? It
 doesn't. It only knows we have documented factory() to return a Base
 object, so that's all the IDE knows; the b() method however is known to
 be there.
 
 
 
 Second, there is always the possibility of a generic __call() method
 which handles the unknown calls to an object. If an object implements
 this method, that makes it even harder for the interpreter to figure out
 if the method-call would result in an error or not.
 
 class A {
 function __call () {
 
 }
 }
 
 $a = new A ();
 $a->whateverWeWish ();
 
 This doesn't generate an error at runtime, so how (moreover; why?)
 should the IDE warn you about something that really isn't a problem?
 
 
 To conclude: you can't look at PHP the way you can look at Java. In Java
 everything is strong typed, even at compile time. In PHP it isn't, types
 can change at runtime, at that's what makes it very hard to do
 strong-type checks in the development environment (before runtime).
 
 
 
 However, i think your problem in this case should actually be fixed by
 refactoring possibilities in the IDE. Imho those could maybe be a bit
 more extensive.
 
 
 
 regards,
 
 drm / Gerard
 |  |  |  | 
| 
| Re: No PHP Compile Errors in eclipse PDT [message #66119 is a reply to message #66054] | Wed, 13 February 2008 12:16  |  | 
| Eclipse User  |  |  |  |  | Hello Gerard, 
 Thank you for your reply. You're right: sometimes you don't no what class
 is implemented, especially when you are working with interfaces. And it's
 good practice to work with interfaces. I'm just studying the design
 patterns in 'PHP Objects, Patterns and Practice' by Matt Zandstra: very
 nice reading.
 
 But very often you just implement a class and not an interface and you
 know the methods and properties of it. In my opion, changing the name of
 the method of a class should result in syntax or compile error's in source
 code that is using it.
 
 If there is any way to make eclipse PDT generating syntax errors in cases
 above, I would use it. Better syntax errors in development then runtime
 errors on the production environment.
 
 Best regards, Mike
 |  |  |  | 
Powered by 
FUDForum. Page generated in 0.05426 seconds