#46348 [Asn->Csd]: constant docs still say you can't define a resource as a constant, but you can
| From: | kalle@php.net | Date: | Tue, 02 Dec 2008 00:21:28 +0000 |
| Subject: | #46348 [Asn->Csd]: constant docs still say you can't define a resource as a constant, but you can | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-1576@lists.php.net to get a copy of this message | ||
ID: 46348
Updated by: kalle@php.net
Reported By: matt at waggoner dot com
-Status: Assigned
+Status: Closed
Bug Type: Documentation problem
Operating System: N/A
PHP Version: Irrelevant
Assigned To: kalle
New Comment:
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.
Thank you for the report, and for helping us make our documentation
better.
Previous Comments:
------------------------------------------------------------------------
[2008-11-05 05:15:30] matt at waggoner dot com
The documentation *does* say it's not possible:
"Only scalar data (boolean, integer, float and string) can be contained
in constants."
I don't know how that can be interpreted to say that resources *can* be
contained in constants. Granted, the next sentence ambiguates things:
"Do not define resource constants."
That phrasing implies that you can, but must not, define resource
constants. If you absolutely could not, it would say "Resource
constants cannot be defined" or something equivalent. However, even in
this interpretation, the two sentences contradict each other: the first
one explicitly says that you CANNOT define resource constants, but the
second one explicitly says that you MUST NOT define resource constants,
and implies that it is possible. Either the documentation must be
changed to unambiguously reflect reality, or the code needs to be
changed to reflect the first sentence, and the second sentence must be
removed.
If we only change the documentation, I suggest the following wording:
"Only scalar data (boolean, integer, float and string) should be
contained in constants. Resources can be defined as constants, but you
should not do this." The problem is that it doesn't explain WHY the
code allows resources to be defined as constants, even though the
documentation is telling you not to.
------------------------------------------------------------------------
[2008-11-05 04:27:16] kalle@php.net
Jakub, im reopening this bug as I need to put on a notice after the
decision thats currently going on internals is final :)
------------------------------------------------------------------------
[2008-11-04 16:43:21] vrana@php.net
Documentation doesn't say it's not possible. It just says to not do it
because it can cause certain problems.
------------------------------------------------------------------------
[2008-10-20 20:54:48] matt at waggoner dot com
Ignore that "Hello!" in the Actual Result section, that was pasted from
the wrong place. The proper Actual Result is:
resource(5) of type (stream)
string(10) "Hello!
<?p"
resource
------------------------------------------------------------------------
[2008-10-20 20:47:30] matt at waggoner dot com
Description:
------------
In the PHP Language Reference section for Constants at
http://us3.php.net/constants it says the following:
"Only scalar data (boolean, integer, float and string) can be contained
in constants. Do not define resource constants."
This is false in both 5.2.5 and 5.2.6. Resources (DB connections, file
handles, etc.) can be defined as constants and will function.
Either the documentation should be changed to match the code, or the
code should be fixed to match the documentation. Bug #29534 seems to
say that the documentation was fixed a couple of years ago, but the docs
seem to still be incorrect.
Reproduce code:
---------------
foo.php:
<?php
error_reporting(E_ALL);
$link = fopen("foo.php", "r");
var_dump($link);
define('FOO', $link);
$x = fread(FOO, 10);
var_dump($x);
echo(gettype(FOO));
fclose(FOO);
?>
Expected result:
----------------
I'd expect an error on line 7, telling me that resources cannot be
defined as constants.
Actual result:
--------------
Hello!
resource(5) of type (stream)
string(10) "Hello!
<?p"
resource
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=46348&edit=1