History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: ZF-329
Type: Improvement Improvement
Status: Resolved Resolved
Resolution: Fixed
Priority: Minor Minor
Assignee: Art Hundiak
Reporter: Gavin
Votes: 0
Watchers: 3
Operations

If you were logged in you would be able to see more operations.
Google issue summary
Zend Framework

Removal of loadInterface() Method

Created: 21/Aug/06 07:46 PM   Updated: 05/Jul/07 02:43 PM
Component/s: Zend_Loader
Affects Version/s: 0.1.5, 0.1.4, 0.1.3
Fix Version/s: 0.7.0

Time Tracking:
Not Specified

Issue Links:
Duplicate
 


 Description  « Hide
There has been confusion over the loadInterface() method in Zend.php. We believe loadInterface() is not needed, and developers should either use require() or require_once() when including files defining interfaces.

Thus loadInterface() is deprecated and will be removed from Zend.php, unless somone provides practical reasons to keep it. Documentation must also be updated to reflect this change.



 All   Comments   Work Log   Change History   FishEye   Crucible      Sort Order: Ascending order - Click to sort in descending order
Darby Felton - 22/Aug/06 09:21 AM
Are we also removing loadClass(), then? Of course, loadClass() cannot load interface classes because it uses class_exists().

Gavin - 22/Aug/06 12:03 PM

Are we also removing loadClass(), then? Of course, loadClass() cannot load interface classes because it uses class_exists().

No. Zend::loadClass() serves a valid purpose by providing a mechanism for factory methods to load classes, but throw exceptions on error conditions.

Loading interfaces is different, since the class using the interfaces should simply use "require_once()" directly in the file containing the source code for the class.


Lee Saferite - 27/Sep/06 04:33 PM
I would think that keeping Zend::loadInterface makes more sense.

Since ZF has a concept of namespaces, and Zend::loadClass understands that, it seems logical to maintain a similar loading system for interfaces.

Basically, if I call:

Zend::loadClass('Zend_Controller_Router');

it seems logical that I should also be able to call:

Zend::loadInterface('Zend_Controller_Router_Interface');

Gavin - 27/Sep/06 04:41 PM
Why use loadInterface() instead of require_once?

Lee Saferite - 27/Sep/06 04:43 PM
Well, why use loadClass()?

If you are abstracting the actual file and using a namespace for your classes, then wouldn't it make more sense to do the same for interfaces?


Lee Saferite - 27/Sep/06 04:55 PM
Sorry if i sounded gruff on my last comment, wasn't intended.

I just think that a common method for utilizing namespaces for classes and interfaces should remain.
The fact that Zend::loadInterface() knows how to translate the name into an actual file exactly like loadClass() seems more coherent.

barring the fact that Zend.php couldn't use that method, every other class in the ZF could use it to load needed interfaces and classes. Although currently the ZF classes seem to use require_once for interfaces instead. Is there a significant speed difference?


Gavin - 27/Sep/06 04:58 PM

Well, why use loadClass()?

If you are abstracting the actual file and using a namespace for your classes, then wouldn't it make more sense to do the same for interfaces?

No. This question was answered in my response above on 22/Aug/06.


Lee Saferite - 27/Sep/06 05:12 PM
Ok, I'll admit, I must be confused. I have read your comments and you seem to say that Zend::loadClass() is really just for factory methods, yet in tutorials on usign ZF they commonly use:
Zend::loadClass('Zend_Controller_Front');

Now, if I understand what you are saying, we should really just use:

require_once('Zend/Controller/Front.php');

And leave Zend::loadClass() to the factory methods?


Gavin - 27/Sep/06 06:16 PM
See the last section on this page.

Lee Saferite - 27/Sep/06 06:26 PM
Cute.
I notice you just added that.
Shouldn't things like Coding Standards be discussed, or are you the final judge on the standards?
And if I disagree with that standard, what would be the correct forum for discussion?

Gavin - 27/Sep/06 10:04 PM
Yes, by chance the ZF team just discussed that section and agreed to it before your posting.

Coding standards are always open for discussion. In fact we specifically moved them to the wiki to encourage improvement and discussion within the community (see numerous past emails on the topic in fw-general).


Christopher Thompson - 28/Sep/06 08:59 PM
I don't think the arguement "No. Zend::loadClass() serves a valid purpose by providing a mechanism for factory methods to load classes, but throw exceptions on error conditions." is exactly valid.

loadClass and the other load classes do a little more than just support factory methods. They convert names to paths and verify that the file and contents are what are being requested. None of them are needed as they are convenience methods.


Gavin - 28/Sep/06 09:15 PM
Hmmm .. in what way is the statement not valid? Is it not true? The statement provides the key reason why loadClass() is needed and should not be removed. Using PHP's require_once statement does allow an error to be thrown. Thus, a key reason exists for using loadClass(). The other reasons are weaker.

Matthew Ratzloff - 01/Oct/06 11:26 AM
I don't understand why this an issue. Is Zend::loadInterface() really detracting from the Zend base class?

I prefer the function over require_once simply because it matches loadClass and does additional error checking. If it didn't exist I would write it myself.


Aleksey V. Zapparov - 02/Oct/06 02:25 AM
IMHO if Zend::loadInterface() is needed by some developers, then loadClass can be extended, for example like this:
static public function loadClass($class, $dirs = null, $isInterface = false)

In Zend classes I think we have to use require_once (not loadClass or loadInterface), because loadClass for me is an external tool. So in project I use require_once only once when calling require_once 'Zend.php'; then I use only Zend::loadClass().

Anyway if some of developers are using loadInterface, why not to leave it? I thought framework developed to make a unified tool or a wraper to frequently used functions

And the main reason, why I post comment is my idea of improvement of Zend::loadClass(), described in ZF-410.
Some child classes are optional. The example is Zend_Config and Zend_Config_Array.


Gavin - 02/Oct/06 11:06 AM
BTW, loadClass() is not IDE/tool friendly, while require_once can be auto-completed by tools, thus providing immediate "code-time" feedback about spelling errors, unlike the runtime exceptions resulting when using loadClass() with a spelling error in its argument.

Aleksey V. Zapparov - 03/Oct/06 03:22 AM
Well. Maybe you're right.
But I gues there are a lot of developers who still be using loadClass and loadInterface...

Bill Karwin - 13/Nov/06 03:13 PM
Changing fix version to 0.6.0.

Gavin - 18/Dec/06 11:42 AM
Fixed in changeset 2387.