Home > Archive > PHP PEAR Questions and Answers > November 2006 > Return values in constructor
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Return values in constructor
|
|
| Eric Bouwers 2006-11-05, 6:58 pm |
| Hi,
I have been working on PHP-Sat, a tool for statically analyzing PHP
source code. This tool currently supports 14 bugpatterns, one of them
finds constructors with a return value. This pattern is partly based
on this thread:
http://beeblex.com/lists/index.php/...s=l:php.pear.qa
in which Michael Wallner reports 11 constructors that return a value.
I examined the stable packages from pear with the use of the tool and
found 13 constructors that (still) return a value. Some of the
constructors are even documented with a '@return' which states that
the constructors actually return these values.
I was wondering whether a return value in a constructor is considered
a bug within Pear. It does not break the code, but it is useless and
could potentially confuse other programmers.
Kind regards,
Eric Bouwers
===
The following projects - files - classes have a constructor that
returns a value:
Archive:
Tar.php - Archive_Tar
Auth:
PrefManager.php - Auth_PrefManager
Crypt/;
CDC.php - Crypt_CBC
DB:
NestedSet.php - DB_NestedSet_Node
Table.php - DB_Table
HTML:
Progress/DM.php - HTML_Progress_DM
Progress.php - HTML_Progress
Table.php - HTML_Table
Mail_Queue:
Queue.php - Mail_Queue
Net_Geo:
Geo.php - Net_Geo
Chemistry:
Coordinates - Science_Chemistry_Coordinates
SOAP:
Value.php - SOAP_Attachment
System:
Mount.php - System_Mount_Entry
| |
| Mark Wiesemann 2006-11-05, 6:58 pm |
| Hi Eric,
Eric Bouwers wrote:
> I have been working on PHP-Sat, a tool for statically analyzing PHP
> source code. This tool currently supports 14 bugpatterns, one of them
> finds constructors with a return value. This pattern is partly based
> on this thread:
> http://beeblex.com/lists/index.php/...s=l:php.pear.qa
> in which Michael Wallner reports 11 constructors that return a value.
>
> I examined the stable packages from pear with the use of the tool and
> found 13 constructors that (still) return a value. Some of the
> constructors are even documented with a '@return' which states that
> the constructors actually return these values.
I can only answer for DB_Table and HTML_Table:
The (very old) @return comment in DB_Table is a little bit bogus, as
@return object DB_Table
is rather obvious. ;-)
The two not empty return statements in the constructor are oversights
and are easy to correct.
The API version check (for HTML_Common) in HTML_Table is rather old and
does not need to stay there.
I'll fix the problems in both packages soon.
Regards,
Mark
|
|
|
|
|