php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #36461 Constants should only be scalars
Submitted: 2006-02-20 14:44 UTC Modified: 2006-02-21 17:10 UTC
From: mgkimsal at gmail dot com Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: Irrelevant OS: All
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mgkimsal at gmail dot com
New email:
PHP Version: OS:

 

 [2006-02-20 14:44 UTC] mgkimsal at gmail dot com
Description:
------------
I realize this is 18 months late, but why is this bogus?

It's not only a winxp problem - this happens on all platforms I've tried (well, win and linux).  Nor is this only a PHP5 problem - it's a problem in the 4 series as well (haven't tested 3).

Either the docs should be changed, or the code behaviour should be changed.  I'm in favor of the latter.  While the 'resource' might be constant - "Resource id #4" might always be "Resource id #4", the state of that resource might change (file reading problems, db connection problems, etc.).   If the value (or the functional state) of something can change, that's not really 'constant', is it?

Also, I'm not sure how resource ID numbers are allocated, so this situation might not happen, but in a resource-intense app, might there be a chance of using a resource, closing it, opening a new one, and getting the same 'id' #?

I only found out about this recently, but it seems wrong, and certainly goes against the documentation.



Reproduce code:
---------------
<?php
$x = mysql_connect('localhost','rt_mgk_user','rt_mgk_pass','rt_mgk');
define('FOO',$x);
if (is_resource(FOO)) {
  echo 'foo is a resource';
} else {
  echo 'foo is not a resource';
}
?>


Expected result:
----------------
foo is not a resource

Actual result:
--------------
foo is a resource

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-02-20 22:38 UTC] philip@php.net
From the manual (php.net/constants):

Only scalar data (boolean, integer, float and string) can be contained in constants.

What documentation are you referring to? A resource type is certainly not scalar.
 [2006-02-21 00:47 UTC] mgkimsal at gmail dot com
The documentation I'm referring to is in define().

http://us2.php.net/define

This gives the impression that you can only define a constant based on what is in the 'constant' page that you reference.  Running the code I provided indicates that a resource handle can be defined into a constant, which is counter to the documentation, or unclear at best.
 [2006-02-21 17:10 UTC] philip@php.net
Wow, I misread your results assuming this wasn't possible. But it is! The following bug report has been reopened so marking this duplicate as bogus.

http://bugs.php.net/bug.php?id=29534

Feel free to discuss there.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jul 07 07:01:33 2025 UTC