#48825 [NEW]: Namespace throws fatal error if any exception is handled within a class
| From: | shiva dot buzz at gmail dot com | Date: | Mon, 06 Jul 2009 23:28:54 +0000 |
| Subject: | #48825 [NEW]: Namespace throws fatal error if any exception is handled within a class | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-139355@lists.php.net to get a copy of this message | ||
From: shiva dot buzz at gmail dot com
Operating system: Windows VISTA
PHP version: 5.3.0
PHP Bug Type: *General Issues
Bug description: Namespace throws fatal error if any exception is handled within a class
Description:
------------
I ran a small example for namespace. I found one Fatal error when the
namespace was been used.
If you pass a invalid email id, that is 'alejandrodomain.com
' $user = new
UserManager\CMS\User('Alejandro','Gervasio','alejandrodomain.com
');
it throws a fatal error saying Exception class can not be found.
PHP Fatal error: Class 'UserManager\CMS\Exception' not found in
C:\user\user.php on line 25
I used the same example listed below with little change;
http://www.devshed.com/c/a/PHP/Using-Namespaces-in-PHP-5/3/
Could you let me know why namespace is not able to recognize the
Exception class.
Reproduce code:
---------------
Filename: user.php
<?php
namespace UserManager\CMS;
class User{
private $firstName;
private $lastName;
private $email;
public function __construct($firstName,$lastName,$email){
if(!$firstName||strlen($firstName)>32){
throw new Exception('Invalid First Name parameter!');
}
if(!$lastName||strlen($lastName)>32){
throw new Exception('Invalid Last Name parameter!');
}
if(!$email||!preg_match("/^.+@.+..+$/",$email)){
throw new Exception('Invalid Email parameter!');
}
$this->firstName=$firstName;
$this->lastName=$lastName;
$this->email=$email;
}
// get user's first name
public function getFirstName(){
return $this->firstName;
}
// get user's last name
public function getLastName(){
return $this->lastName;
}
// get user's email
public function getEmail(){
return $this->email;
}
?>
RunUser.php
<?php
include_once "user.php";
use UserManager\CMS;
try{
// create new instance of 'User' class by using the specified namespace
$user = new
UserManager\CMS\User('Alejandro','Gervasio','alejandrodomain.com');
// display user data
echo 'First Name: '.$user->getFirstName().'<br />';
echo 'Last Name: '.$user->getLastName().'<br />';
echo 'Email: '.$user->getEmail().'<br />';
$user->getValueN();
}
catch(Exception $e){
echo $e->getMessage();
exit();
}
?>
Expected result:
----------------
Invalid Email parameter
Actual result:
--------------
PHP Fatal error: Class 'UserManager\CMS\Exception' not found in
C:\user\user.php on line 25
--
Edit bug report at http://bugs.php.net/?id=48825&edit=1
--
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=48825&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=48825&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=48825&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=48825&r=fixedcvs
Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=48825&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=48825&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=48825&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=48825&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=48825&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=48825&r=support
Expected behavior: http://bugs.php.net/fix.php?id=48825&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=48825&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=48825&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=48825&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=48825&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=48825&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=48825&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=48825&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=48825&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=48825&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=48825&r=mysqlcfg