[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.tools.pdt] Re: Nested Class/Function and Code Completion

Andrew Thompson wrote:

> Why would you use constants here to check if the file is defined?
> Looks like you are trying to do something similar to C/C++ header
> file inclusion.

Simply because when you deal with a large project and lets just say...
under skilled developers when projects get created, it provides a
simple way to protect from nested includes, where developers 'forget'
to use require_once/include_once.  This is done simlly for maintenance
complexity.  It has since been reworked out of the code and all 'bad'
includes seded out of the projects and the nesting removed from library
code.

The point is, time required to fix all existing project's includes vs
protecting the include itself by nesting is pretty obvious.


> You can use require_once/include_once to include the file instead.

Indeed.

> 
> I'd expect conditional declaration is bad practice anyway. If there
> were any need to do it, it could surely be done another way, e.g.
> subclassing Fish for different implementations.

Mentioning Subclassing here is kind of irrelivant as the code below is
a basic example demonstrating the behaviour of PDT.

The same conditional declaration would be used to define functions such
as if you were implementing, conditionally, memory_get_usage() in a
library designed to work with 'older' versions of php that do not have
it (<= 4.3.1, or <= 5.2.1 compiled without --enable-memory-limit).

So again, here the point is, there are perfectly valid reasons why you
would write conditional declarations.

> 
> Andy
> 
> Ben Clifton wrote:
> > Code Completion breaks when a class or function definition is nested
> > inside an if statement.
> > 
> > Case:
> > 
> > file1.php
> > 
> > if( !defined( 'FILE1' ) {
> > define( 'FILE1', true );
> > 
> > class Fish { public $dead; }
> > 
> > }
> > 
> > 
> > file2.php
> > 
> > require_once( 'file1.php' );
> > 
> > $fish = new Fish(); // Code Completion fails to find class Fish
> > $fish->dead = true; // Code Completion finds dead varibale in ...
> > // instance of class Fish
> > 



--