#28102 [Opn->Ver]: defining a resource as a constant

From: Date: Sun, 25 Apr 2004 18:29:46 +0000
Subject: #28102 [Opn->Ver]: defining a resource as a constant
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-58740@lists.php.net to get a copy of this message
ID: 28102 Updated by: nlopess@php.net Reported By: dv at josheli dot com -Status: Open +Status: Verified -Bug Type: Documentation problem +Bug Type: Zend Engine 2 problem Operating System: Windows PHP Version: Irrelevant New Comment: Maybe there an engine error here. Take a look at this code: <? $tidy = new tidy; define('aa', $tidy); print_r(AA); ?> outputs: Warning: Constants may only evaluate to scalar values in C:\cygwin\home\Nuno\constants.php on line 3 Call Stack: 0.0012 1. {main}() C:\cygwin\home\Nuno\constants.php:0 0.0014 2. define('aa', class tidy { public $errorBuffer = NULL; public $va lue = NULL }) C:\cygwin\home\Nuno\constants.php:3 Notice: Use of undefined constant AA - assumed 'AA' in C:\cygwin\home\Nuno\constants.php on line 4 Call Stack: 0.0012 1. {main}() C:\cygwin\home\Nuno\constants.php:0 Variables in local scope: $tidy = class tidy { public $errorBuffer = NULL; public $value = NULL } AA 1) It seems that in fact this works, but outputs a couple of errors and echoes the name of the constant, too. Need a fix in the engine. 2) constants are suposed to scalar data or they may have objects/resources? Previous Comments: ------------------------------------------------------------------------ [2004-04-22 08:28:47] dv at josheli dot com Description: ------------ http://www.php.net/manual/en/language.constants.php "Only scalar data (boolean, integer, float and string) can be contained in constants." http://www.php.net/manual/en/function.mysql-connect.php "resource mysql_connect ( ... )" According to the documentation, "Expected result" is an E_NOTICE error or something, but I guess the "Actual result" below implies that a mysql link "resource" is actually an integer (4?). perhaps the documentation in either of the two places listed above, or in the define() man page, should reflect this fact? Reproduce code: --------------- $dbLink = mysql_connect($dbServerName, $dbUser, $dbPassword); define('DB_LINK',$dbLink); var_dump(DB_LINK); echo gettype(DB_LINK); Expected result: ---------------- see above. Actual result: -------------- resource(4) of type (mysql link) resource ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=28102&edit=1

« previous php.bugs (#58740) next »