Edit report at http://bugs.php.net/bug.php?id=47872&edit=1
ID: 47872 Comment by: iffzy at atomar dot de Reported by: kwutzke at web dot de Summary: PHP 5.3+ support for namespace wildcards (use statement) Status: Bogus Type: Feature/Change Request Package: Feature/Change Request Operating System: all PHP Version: 5.3.0RC1 Block user comment: N Private report: N New Comment: It may be a major slowdown when used by idiots. But sometimes this limitation it a major nuisance. I don't need a f*****g nanny for this :/ (yeah I know.. I should silently switch to python.. feels like flogging a dead horse..) Previous Comments: ------------------------------------------------------------------------ [2009-04-03 19:40:40] johan...@php.net We have no class loading mechanism like Java but need the class names while compiling the PHP script. Offering an import foo\* would be a a major slowdown. ------------------------------------------------------------------------ [2009-04-02 02:55:05] kwutzke at web dot de Another option, which I can't quite assess, would be to always (silently) use the root namespace. For some reason I don't believe this is a good idea in PHP. Maybe because, as seen in my example, is the ability to expand the root/global namespace with other (own) classes. ------------------------------------------------------------------------ [2009-04-02 02:50:20] kwutzke at web dot de Other examples of use wildcards are: use \namespace2\*; use \otherns\*; use \myown\sub\*; use \myown\sub\subsub\*; ------------------------------------------------------------------------ [2009-04-02 02:44:11] kwutzke at web dot de Description: ------------ When using namespaces you always have to put the exact 'use \ClassName' statement into the code. This list of dependencies can become quite large in some classes. To relieve programmers from having to manually put use statements to the top (or elsewhere) a namespace wildcard should be added to the language. Much like in Java, where in stead of writing import java.awt.Image; import javax.swing.JTextField; import javax.swing.JComboBox; import javax.swing.JSpinner; import javax.swing.JCheckBox; import javax.swing.JRadioButton; import javax.swing.JMenuItem; import javax.swing.JMenu; import javax.swing.JMenuBar; one could write import java.awt.*; import javax.swing.*; This saves a lot of time while writing the code. An IDE (plugin) might replace the wildcards with the actually used classes. Wrting use \*; seems natural to me. Don't know how much this RFE is possible language-wise. It would however make lots of sense for PHP 5.3. I'm not sure if this is the right place to ask for a language enhancement of this caliber. Reproduce code: --------------- <?php namespace whatever; //in dir whatever //use \*; <- why not??? //PHP standard classes use \Exception; //ZF classes use \Zend_Version; class ZfTools { public static function checkVersion($strRequiredVersion = '1.5.1') { switch ( Zend_Version::compareVersion($strRequiredVersion) ) { case -1: //required is older return true; case 0: //equal case 1: //newer return false; default: //should never be executed throw new Exception('Error comparing Zend Framework version!'); } } } ?> Expected result: ---------------- use \*; would compile so that Zend_Version and Exception can be used without leading backslashes. Actual result: -------------- use \*; Generates a parse error "Parse error: parse error, expecting `T_STRING' in C:\dev\apache\htdocs\whatever\ZfTools.php on line 5" ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=47872&edit=1