Zend Framework

Zend_Validate::is() should not fall back to Zend_Loader::loadClass

Details

  • Type: Improvement Improvement
  • Status: Resolved Resolved
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 1.9.5
  • Fix Version/s: 1.10.0
  • Component/s: Zend_Validate
  • Labels:
    None

Description

Currently Zend_Validate::is() checks if validator class exists using class_exists($className).
If it doesn't then Zend_Validate::is() falls back to the Zend_Loader::loadClass($className).
This behavior generates "Failed opening" warnings if multiple namespaces are used.

Sample code:
Zend_Validate::is("2009-01-01", 'Date', array(),array('FirstNamespace', 'SecondNamespace'))

Result:
Warning: include() [function.include]: Failed opening 'FirstNamespace/Date.php' for inclusion (include_path='...') in ZendFramework-1.9.5/library/Zend/Loader.php on line 83

My opinion is that Zend_Validate::is() should not fall back to the Zend_Loader::loadClass, since all namespaces (since ZF 1.8 as far as I remember) must have all respective namespace loaders registered via the Zend_Loader_Autoloader->pushAutoloader method.

When the validator class is not defined after all namespaces are checked then "Validate class not found from basename '$classBaseName'" exception sould be generated.

To sum up:
In my opinion it's class_exists (via namespace loaders) job to load desired validator class.

Activity

Hide
Thomas Weidner added a comment -

class_exists does not load files when no autoloader is set.

It is a php method which just checks if a given class exists or not.
When you think that PHP itself should add class loading within class_exists then please fill in an issue at PHP.

Additionally we should and will not duplicate Zend_Loader within Zend_Validate.

Show
Thomas Weidner added a comment - class_exists does not load files when no autoloader is set. It is a php method which just checks if a given class exists or not. When you think that PHP itself should add class loading within class_exists then please fill in an issue at PHP. Additionally we should and will not duplicate Zend_Loader within Zend_Validate.
Hide
ChieftainY2k added a comment -

I was referring to the case when autoloader is set by the Zend_Loader_Autoloader.

Show
ChieftainY2k added a comment - I was referring to the case when autoloader is set by the Zend_Loader_Autoloader.
Hide
Thomas Weidner added a comment - - edited

And when no autoloader is set then your case would no longer work because using namespaces is independently from a set autoloader.

Show
Thomas Weidner added a comment - - edited And when no autoloader is set then your case would no longer work because using namespaces is independently from a set autoloader.
Hide
Thomas Weidner added a comment -

Changed with r19026

Show
Thomas Weidner added a comment - Changed with r19026

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: