NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
A copmile like feature. (Run instant error analysis)
Veteran

Joined: 30 Nov 2006
Posts: 186
Reply with quote
Hi

I was thinking.

Does PHPed have a compile like feature that can check the code for stupid mistakes ?

In the Tools menu there is a menuitem called : "Run instant error analysis"

I have tried that, but it does not seam to do anything.

To test it I have created an abstract class with two abstract methods, but have not implemented the methods in the child classes. If it was a compile feature, I would expect it to produce a warning or error, telling me that I have to implement the methods.
View user's profileFind all posts by hgrSend private message


Joined: 07 Mar 2007
Posts: 44
Location: Lithuania
Reply with quote
I've not spotted such a feature of phpEd until hgr mentioned here. Tested this, but, unfortunatelly, nothing happened.

Is this a bug, such feature should be implemented, I think this should be almost the same as in Zend Studio "Analyze code" feature.

Cheers.
View user's profileFind all posts by thunder-ltuSend private messageVisit poster's website
Site Admin

Joined: 13 Jul 2003
Posts: 8334
Reply with quote
Quote:
Run instant error analysis


PhpED runs this analysis by default. For example if you enter code below:

<?
$a = 5
$b = c
?>

it will underline $b because there is no semicolon after 5

If for any reason you turn this feature off in tools->settings->code insight, you may still run such checks manually. That's what the menu option is for.

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website
Veteran

Joined: 30 Nov 2006
Posts: 186
Reply with quote
Ok..

So a compile like feature, that will check the code more deeply (missing function overloads etc), would be a feature request right?
View user's profileFind all posts by hgrSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8334
Reply with quote
What I referred to is compiler. It compiles script and checks for its correctness. Other things that you asked about can't be verified in compile-time. They are pure run-time errors.

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website
Veteran

Joined: 30 Nov 2006
Posts: 186
Reply with quote
Well not true.

You can see if a interface is implemented, if an abstract method on the base class is indeed implemented in the child class or not.

If you use a type in the function parameter that is not defined i.e

public function (mytype $variable)

and stuff like that, would be great if you could catch before runtime.
View user's profileFind all posts by hgrSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8334
Reply with quote
okay,
even if a class does not implement an interface it's not a problem at all.
The problem may happen only if you use its instance as this interface.
But instance is a run-time thing, isn't it?

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website
Veteran

Joined: 30 Nov 2006
Posts: 186
Reply with quote
Well yes.

But imagine if you had such a tool to eliminate dummy errors in OOP.

If you do not implement an interface you should get a runtime error, because you MUST implement the methods in an interface in OOP.

If PHP5 does not complain about this runtime then the OOP part of php is not complete.
The same goes for Abstract functions, they are declared in the abstract class, but any child classes that extends the abstract class MUST implement the abstract functions.

All these errors could be caught by analyzing the source code, it does not have to be runtime.
View user's profileFind all posts by hgrSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8334
Reply with quote
Quote:
The same goes for Abstract functions, they are declared in the abstract class, but any child classes that extends the abstract class MUST implement the abstract functions

I can only repeat, if a class does not implement an abstract method defined in its parent, it is not a problem at all. For example you may define them in a class derived from this. Why not?

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website
Veteran

Joined: 30 Nov 2006
Posts: 186
Reply with quote
dmitri wrote:
Quote:
The same goes for Abstract functions, they are declared in the abstract class, but any child classes that extends the abstract class MUST implement the abstract functions

I can only repeat, if a class does not implement an abstract method defined in its parent, it is not a problem at all. For example you may define them in a class derived from this. Why not?


Well it should be a problem. It is bad OOP design if child classes does not implement abstract methods. A warning by a compile feature would be nice.

Better code, fewer errors.

PHP is lacking strict type checking, compared to C# and Java. It would be nice to have a feature that will catch the most common mistakes, that are a little more complicated than forgetting a ;
View user's profileFind all posts by hgrSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8334
Reply with quote
Quote:
Well it should be a problem. It is bad OOP design if child classes does not implement abstract methods. A warning by a compile feature would be nice

why?
Say I have a class named OBJECT which has two abstracts MOVE and DRAW defined.
I can derive FLYINGOBJECT and define MOVE
then I will derive FLY and define DRAW.
I'm not going to create any instances of FLYINGOBJECT.
What's wrong with this?
Why would IDE blame such code and tell me that FLYINGOBJECT must have DRAW?

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website
Veteran

Joined: 30 Nov 2006
Posts: 186
Reply with quote
dmitri wrote:
Quote:
Well it should be a problem. It is bad OOP design if child classes does not implement abstract methods. A warning by a compile feature would be nice

why?
Say I have a class named OBJECT which has two abstracts MOVE and DRAW defined.
I can derive FLYINGOBJECT and define MOVE
then I will derive FLY and define DRAW.
I'm not going to create any instances of FLYINGOBJECT.
What's wrong with this?
Why would IDE blame such code and tell me that FLYINGOBJECT must have DRAW?


Well because if the DRAW function only makes sense for the FLY object and

Move only makes sense for FLYINGOBJECT then they have nothing to do on the base OBJECT class, they belong to the CHILD class only.

Base classes should only have functions that are general for all child classes. If a function is a general function but can not be implementet on the Base class because the individual implementation should basicly be different for each child, it must be declared Abstract and this enforces that child classes MUST implement these functions.

Have a look at this URL http://www.developer.com/lang/php/article.php/3604111
View user's profileFind all posts by hgrSend private message
A copmile like feature. (Run instant error analysis)
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 2  

  
  
 Reply to topic