note 89984 added to language.namespaces.basics

From: Date: Wed, 01 Apr 2009 02:16:49 +0000
Subject: note 89984 added to language.namespaces.basics
Groups: php.notes 
Request: Send a blank email to php-notes+get-152675@lists.php.net to get a copy of this message
I wonder why "use \" doesn't or shouldn't work to access global classes etc. ... I put up a small Zend Framework example to demonstrate (put file ZfTools into ./kapi dir): <?ph p namespace kapi; class ZfTools { public static function checkVersion($strRequiredVersion = '1.5.1') { //use \; //switch ( Zend_Version::compareVersion($strRequiredVersion) ) switch ( \Zend_Version::compareVersion($strRequiredVersion) ) { case -1: //older return true; case 0: //equal case 1: //newer return false; default: //should never be executed //throw new Exception('Error comparing Zend Framework version!'); throw new \Exception('Error comparing Zend Framework version!'); } } } ?> Not being able to do so produces leading backslashes all the time which is annoying. The outcommented lines are what I had expected and still find more natural. Here's a test program (put it into the root dir, can be index.php): <?ph p require_once 'Zend/Loader.php'; Zend_Loader::registerAutoload(); use kapi\ZfTools; echo 'The installed Zend Framework version is ' . Zend_Version::VERSION . '.<br />'; $isZfVersionOk = false; try { $isZfVersionOk = ZfTools::checkVersion(); } catch ( Exception $e ) { echo $e->getMessage() . '<br />'; } echo 'Version ' . Zend_Version::VERSION . ' is ' . ($isZfVersionOk ? 'ok.' : 'not ok!') . '<br />'; ?> ---- Server IP: 69.147.83.197 Probable Submitter: 84.167.248.220 ---- Manual Page -- http://www.php.net/manual/en/language.namespaces.basics.php Edit -- https://master.php.net/note/edit/89984 Del: integrated -- https://master.php.net/note/delete/89984/integrated Del: useless -- https://master.php.net/note/delete/89984/useless Del: bad code -- https://master.php.net/note/delete/89984/bad+code Del: spam -- https://master.php.net/note/delete/89984/spam Del: non-english -- https://master.php.net/note/delete/89984/non-english Del: in docs -- https://master.php.net/note/delete/89984/in+docs Del: other reasons-- https://master.php.net/note/delete/89984 Reject -- https://master.php.net/note/reject/89984 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#152675) next »