#32370 [Fbk->Bgs]: Object Constants
| From: | helly@php.net | Date: | Sat, 19 Mar 2005 11:47:41 +0000 |
| Subject: | #32370 [Fbk->Bgs]: Object Constants | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-75516@lists.php.net to get a copy of this message | ||
ID: 32370
Updated by: helly@php.net
Reported By: codebowl at gmail dot com
-Status: Feedback
+Status: Bogus
Bug Type: Class/Object related
-Operating System: Windows XP Pro SP 2
+Operating System: *
PHP Version: 5.0.3
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
The code part that deals with consts is correct as the test script
below shows. I guess you are accessing both
through 'error_type' of $this->_tpl if that's the case rethink your
logic. If not rethink what you thought was the error and check your
code again.
--TEST--
Bug #32370 (Object Constants)
--FILE--
<?php
class SvEx extends Exception
{
const ERR_TYPE = "Unknown Error";
const ERR_DESC = "There has been an error.";
protected $_msg;
protected $_error;
public function __construct($error = null)
{
$this->_error = array(
'type' => self::ERR_TYPE,
'description' => self::ERR_DESC
);
$this->_msg = $error;
parent::__construct($this->_msg);
}
public function getType()
{
return $this->_error['type'];
}
public function getDesc()
{
return $this->_error['description'];
}
}
class ApplicationEx extends SvEx
{
const ERR_TYPE = "Application Error";
const ERR_DESC = "An Application Error!";
public function __construct($msg = null)
{
parent::__construct($msg);
$this->_error['type'] = self::ERR_TYPE;
$this->_error['description'] = self::ERR_DESC ;
}
}
try
{
throw new SvEx();
}
catch(Exception $e)
{
echo "Type: " . $e->getType() . "\n";
echo "Desc: " . $e->getDesc() . "\n";
}
try
{
throw new ApplicationEx();
}
catch(Exception $e)
{
echo "Type: " . $e->getType() . "\n";
echo "Desc: " . $e->getDesc() . "\n";
}
?>
===DONE===
--EXPECT--
Type: Unknown Error
Desc: There has been an error.
Type: Application Error
Desc: An Application Error!
===DONE===
Previous Comments:
------------------------------------------------------------------------
[2005-03-19 12:17:02] tony2001@php.net
Could you provide a smaller. but still working & complete reproduce
script, please ?
------------------------------------------------------------------------
[2005-03-19 00:58:23] codebowl at gmail dot com
http://codebowl.dontexist.net/source/SvEx.phps
is the url to the SvEx class file, there was a typo with the Sc part of
the filename.
------------------------------------------------------------------------
[2005-03-19 00:57:01] codebowl at gmail dot com
Description:
------------
I have 2 class files, one that extends the built in Exceptions class
and one that extends this class
Built In Exceptions
|
|
+- SvEx Class
|
|
+- ApplicationEx Class
The problem lies in class constants.
The SvEx class and Application Class both have thier own constants
named ERR_TYPE and ERR_DESC for some reason when i throw an
ApplicationEx Exception it is using the constants from the SvEx
Exception class.
Reproduce code:
---------------
You can see the code files here
http://codebowl.dontexist.net/source/ScEx.phps
http://codebowl.dontexist.net/source/Application.phps
http://codebowl.dontexist.net/source/Trigger.phps
Expected result:
----------------
I would expect that it would set the $this->_error['type'] and ['desc']
with the appropriate constant values. When i throw an ApplicationEx it
should use the ApplicationEx::ERR_TYPE etc..
Everything else set's properly such as the error message blah blah, you
can see an example of the results here
http://codebowl.dontexist.net/clients/JVMedia/SimonVolkov/global.php
Actual result:
--------------
For some reason it is setting them to the values in the SvEx Exception
Class
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=32370&edit=1