php.net |  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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: codebowl at gmail dot com
New email:
PHP Version: OS:

 

 [2005-03-19 00:57 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-03-19 00:58 UTC] 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 12:17 UTC] tony2001@php.net
Could you provide a smaller. but still working & complete reproduce script, please ?
 [2005-03-19 12:47 UTC] helly@php.net
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===

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 05:01:29 2024 UTC