#46348 [Asn->Bgs]: constant docs still say you can't define a resource as a constant, but you can

From: Date: Tue, 04 Nov 2008 16:43:21 +0000
Subject: #46348 [Asn->Bgs]: 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-1316@lists.php.net to get a copy of this message
ID: 46348 Updated by: vrana@php.net Reported By: matt at waggoner dot com -Status: Assigned +Status: Bogus Bug Type: Documentation problem Operating System: N/A PHP Version: Irrelevant Assigned To: kalle New Comment: Documentation doesn't say it's not possible. It just says to not do it because it can cause certain problems. Previous Comments: ------------------------------------------------------------------------ [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

« previous php.doc.bugs (#1316) next »