#46348 [Opn]: constant docs still say you can't define a resource as a constant, but you can
| From: | matt at waggoner dot com | Date: | Mon, 20 Oct 2008 20:54:49 +0000 |
| Subject: | #46348 [Opn]: 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-1219@lists.php.net to get a copy of this message | ||
ID: 46348
User updated by: matt at waggoner dot com
Reported By: matt at waggoner dot com
Status: Open
Bug Type: Documentation problem
Operating System: N/A
PHP Version: Irrelevant
New Comment:
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
Previous Comments:
------------------------------------------------------------------------
[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