For Programmers: Free Programming Magazines  


Home > Archive > PHP Documentation > February 2006 > #36461 [Fbk->Opn]: Constants should only be scalars









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author #36461 [Fbk->Opn]: Constants should only be scalars
mgkimsal at gmail dot com

2006-02-20, 6:56 pm

ID: 36461
User updated by: mgkimsal at gmail dot com
Reported By: mgkimsal at gmail dot com
-Status: Feedback
+Status: Open
Bug Type: Documentation problem
Operating System: All
PHP Version: Irrelevant
New Comment:

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.


Previous Comments:
------------------------------------------------------------------------

[2006-02-20 22:38:08] 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-20 14:44:48] 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


------------------------------------------------------------------------


--
Edit this bug report at http://bugs.php.net/?id=36461&edit=1
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com