|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32370 Object Constants
Submitted: 2005-03-19 00:57 UTC Modified: 2005-03-19 12:47 UTC
From: codebowl at gmail dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.0.3 OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: codebowl at gmail dot com
New email:
PHP Version: OS:


 [2005-03-19 00:57 UTC] codebowl at gmail dot com
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

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

Actual result:
For some reason it is setting them to the values in the SvEx Exception Class


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-03-19 00:58 UTC] codebowl at gmail dot com

is the url to the SvEx class file, there was a typo with the Sc part of the filename.
 [2005-03-19 12:17 UTC]
Could you provide a smaller. but still working & complete reproduce script, please ?
 [2005-03-19 12:47 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

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.

Bug #32370 (Object Constants)

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;

	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)

		$this->_error['type'] = self::ERR_TYPE;
		$this->_error['description'] = self::ERR_DESC ;

	throw new SvEx();
catch(Exception $e)
	echo "Type: " . $e->getType() . "\n";
	echo "Desc: " . $e->getDesc() . "\n";

	throw new ApplicationEx();
catch(Exception $e)
	echo "Type: " . $e->getType() . "\n";
	echo "Desc: " . $e->getDesc() . "\n";

Type: Unknown Error
Desc: There has been an error.
Type: Application Error
Desc: An Application Error!

PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sat Sep 19 20:01:33 2020 UTC