note 89984 deleted from language.namespaces.basics by danbrown
| From: | danbrown@php.net | Date: | Wed, 01 Apr 2009 02:17:52 +0000 |
| Subject: | note 89984 deleted from language.namespaces.basics by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-152676@lists.php.net to get a copy of this message | ||
Note Submitter: kwutzke att web dott de
----
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 />';
?>