php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #18872 Improper handling of class constants used as default function argument values
Submitted: 2002-08-12 23:27 UTC Modified: 2003-06-15 09:42 UTC
From: optikSmoke at subdimension dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 5.0.0-dev OS: Mandrake 8.2 (linux 2.4.18)
Private report: No CVE-ID: None
 [2002-08-12 23:27 UTC] optikSmoke at subdimension dot com
I am using CVS from August 12, compiled with Zend2, as a   
module in Apache 1.3.23. My problem is this: When I use a   
class constant as the default value to an argument in a   
function, the first time I call the function (omitting the   
argument), PHP correctly uses the value of the constant   
for the value of the omitted argument. The second time I   
call the same function (again omitting the argument), PHP   
uses a slightly-garbled form of the name of the class   
constant, instead of the value of the constant. For   
example:   
  
<?   
class FooBar {   
	const BIFF = 3;   
}   
   
function foo($biff = FooBar::BIFF) {   
	echo $biff . "\n";   
}   
   
foo();   
foo();   
?>   
  
The expected output of this is (obviously):   
3   
3   
  
The output I get is:   
3   
foobar :BIFF  
  
(The space before ":BIFF" should be a non-printing  
character, rendered as a box on my system, but I'm not  
sure if it will come through properly :)  
  
This error does not occur when using regular "define()'d"  
constants. For example, if I replaced FooBar::BIFF with a  
constant BIFF, I get the expected output (no garbled  
constant names, "3" is displayed by each call to foo()).  

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-06-15 09:42 UTC] stas@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 08:01:29 2024 UTC