Edit report at https://bugs.php.net/bug.php?id=28102&edit=1

 ID:                 28102
 Comment by:         lucas dot ekrause at gmail dot com
 Reported by:        dv at josheli dot com
 Summary:            defining a resource as a constant
 Status:             Not a bug
 Type:               Bug
 Package:            Scripting Engine problem
 Operating System:   Windows
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

"is_scalar() does not consider resource type values to be scalar as resources 
are 
abstract datatypes which are currently based on integers. (is_scalar man page, 
note section, http://php.net/manual/en/function.is-scalar.php)

The page also says that you shouldn't rely on the described behavior:
"This implementation detail should not be relied upon, as it may change."


Previous Comments:
------------------------------------------------------------------------
[2004-04-25 23:48:39] dv at josheli dot com

what about the original bug report? it's a documentation error or just a magic 
feature?

------------------------------------------------------------------------
[2004-04-25 20:51:09] der...@php.net

1. It prints "AA" because PHP will convert an undefined constant to a string. 
(and throws a warning "Notice: Use of undefined constant AA - assumed 'AA'")

2. Constants are supposed to be scalar only.

No bug here Nuno.

------------------------------------------------------------------------
[2004-04-25 20:29:44] nlop...@php.net

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?

------------------------------------------------------------------------
[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 https://bugs.php.net/bug.php?id=28102&edit=1

Reply via email to