php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28102 defining a resource as a constant
Submitted: 2004-04-22 08:28 UTC Modified: 2004-04-25 23:48 UTC
From: dv at josheli dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: Irrelevant OS: Windows
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: dv at josheli dot com
New email:
PHP Version: OS:

 

 [2004-04-22 08:28 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-04-25 20:29 UTC] nlopess@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-25 20:51 UTC] derick@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 23:48 UTC] dv at josheli dot com
what about the original bug report? it's a documentation error or just a magic feature?
 [2013-06-28 15:33 UTC] lucas dot ekrause at gmail dot com
"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."
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 19 14:01:32 2024 UTC