Ask a Question related to PHP Bugs, Design and Development.
-
smlerman at gmail dot com #1
#40692 [NEW]: Trying to use boolean as array doesn't give an error
From: smlerman at gmail dot com
Operating system: Any
PHP version: 5.2.1
PHP Bug Type: Scripting Engine problem
Bug description: Trying to use boolean as array doesn't give an error
Description:
------------
If you try to use a boolean as an array (which most likely means an error
occurred somewhere), the value is correctly returned as NULL, but no error
message is reported. Obviously not a major problem, but it would make
debugging a little easier.
Reproduce code:
---------------
<?php
var_dump(error_reporting());
$a = false;
var_dump($a[0]);
$b = (string)$a;
var_dump($b[0]);
?>
Expected result:
----------------
int(8191)
[Something like] Notice: Cannot use boolean as array in C:\Documents and
Settings\...\boolean_array.php on line 5
NULL
Notice: Uninitialized string offset: 0 in C:\Documents and
Settings\...\boolean_array.php on line 8
string(0) ""
Actual result:
--------------
int(8191)
NULL
Notice: Uninitialized string offset: 0 in C:\Documents and
Settings\Scott\My Documents\Test Files\boolean_array.php on line 8
string(0) ""
--
Edit bug report at [url]http://bugs.php.net/?id=40692&edit=1[/url]
--
Try a CVS snapshot (PHP 4.4): [url]http://bugs.php.net/fix.php?id=40692&r=trysnapshot44[/url]
Try a CVS snapshot (PHP 5.2): [url]http://bugs.php.net/fix.php?id=40692&r=trysnapshot52[/url]
Try a CVS snapshot (PHP 6.0): [url]http://bugs.php.net/fix.php?id=40692&r=trysnapshot60[/url]
Fixed in CVS: [url]http://bugs.php.net/fix.php?id=40692&r=fixedcvs[/url]
Fixed in release: [url]http://bugs.php.net/fix.php?id=40692&r=alreadyfixed[/url]
Need backtrace: [url]http://bugs.php.net/fix.php?id=40692&r=needtrace[/url]
Need Reproduce Script: [url]http://bugs.php.net/fix.php?id=40692&r=needscript[/url]
Try newer version: [url]http://bugs.php.net/fix.php?id=40692&r=oldversion[/url]
Not developer issue: [url]http://bugs.php.net/fix.php?id=40692&r=support[/url]
Expected behavior: [url]http://bugs.php.net/fix.php?id=40692&r=notwrong[/url]
Not enough info: [url]http://bugs.php.net/fix.php?id=40692&r=notenoughinfo[/url]
Submitted twice: [url]http://bugs.php.net/fix.php?id=40692&r=submittedtwice[/url]
register_globals: [url]http://bugs.php.net/fix.php?id=40692&r=globals[/url]
PHP 3 support discontinued: [url]http://bugs.php.net/fix.php?id=40692&r=php3[/url]
Daylight Savings: [url]http://bugs.php.net/fix.php?id=40692&r=dst[/url]
IIS Stability: [url]http://bugs.php.net/fix.php?id=40692&r=isapi[/url]
Install GNU Sed: [url]http://bugs.php.net/fix.php?id=40692&r=gnused[/url]
Floating point limitations: [url]http://bugs.php.net/fix.php?id=40692&r=float[/url]
No Zend Extensions: [url]http://bugs.php.net/fix.php?id=40692&r=nozend[/url]
MySQL Configuration Error: [url]http://bugs.php.net/fix.php?id=40692&r=mysqlcfg[/url]
smlerman at gmail dot com Guest
-
#39904 [NEW]: string -> boolean conversion of "\0" could give FALSE
From: zizka at seznam dot cz Operating system: PHP version: 5.2.0 PHP Bug Type: Feature/Change Request Bug description: ... -
HTTP Service give me error.......
Dear Friends, I have posted my query on flex builder, but now i think that this is the right place to post it.... I develop a smaple login... -
why does ¬ give me an error
i am trying to edit the "list within a list" example but every time i edit any code i get .... script error: operand expected set record... -
response.redirect give error http 404
Hi All, IIS.4 After I installed the latest windows update MS03- 026, MS03-024, MS03-023, Q811114, Q815021, Q816093, 814078, 811493, q329414 and... -
array full of info, but won't give any up in while loop, each()
Hi lawrence! On 6 Jul 2003 14:17:52 -0700, lkrubner@geocities.com (lawrence) wrote: I found two each in this post. Try reset() between them. ... -
iliaa@php.net #2
#40692 [Opn->Bgs]: Trying to use boolean as array doesn't give an error
ID: 40692
Updated by: [email]iliaa@php.net[/email]
Reported By: smlerman at gmail dot com
-Status: Open
+Status: Bogus
Bug Type: Scripting Engine problem
Operating System: Any
PHP Version: 5.2.1
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
[url]http://www.php.net/manual/[/url] and the instructions on how to report
a bug at [url]http://bugs.php.net/how-to-report.php[/url]
PHP is not type strict.
Previous Comments:
------------------------------------------------------------------------
[2007-03-02 16:20:40] smlerman at gmail dot com
Description:
------------
If you try to use a boolean as an array (which most likely means an
error occurred somewhere), the value is correctly returned as NULL, but
no error message is reported. Obviously not a major problem, but it
would make debugging a little easier.
Reproduce code:
---------------
<?php
var_dump(error_reporting());
$a = false;
var_dump($a[0]);
$b = (string)$a;
var_dump($b[0]);
?>
Expected result:
----------------
int(8191)
[Something like] Notice: Cannot use boolean as array in C:\Documents
and Settings\...\boolean_array.php on line 5
NULL
Notice: Uninitialized string offset: 0 in C:\Documents and
Settings\...\boolean_array.php on line 8
string(0) ""
Actual result:
--------------
int(8191)
NULL
Notice: Uninitialized string offset: 0 in C:\Documents and
Settings\Scott\My Documents\Test Files\boolean_array.php on line 8
string(0) ""
------------------------------------------------------------------------
--
Edit this bug report at [url]http://bugs.php.net/?id=40692&edit=1[/url]
iliaa@php.net Guest
-
smlerman at gmail dot com #3
#40692 [Bgs->Opn]: Trying to use boolean as array doesn't give an error
ID: 40692
User updated by: smlerman at gmail dot com
Reported By: smlerman at gmail dot com
-Status: Bogus
+Status: Open
Bug Type: Scripting Engine problem
Operating System: Any
PHP Version: 5.2.1
New Comment:
Yeah, in 6 years of programming PHP, I never noticed that it isn't a
strictly typed language. Trying to use an undefined offset of an array
gives an error message. Trying to use a non-existant character index of
a string gives an error message. So what is the boolean being converted
to such that using an incorrect offset isn't an error?
Previous Comments:
------------------------------------------------------------------------
[2007-03-03 15:58:22] [email]iliaa@php.net[/email]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
[url]http://www.php.net/manual/[/url] and the instructions on how to report
a bug at [url]http://bugs.php.net/how-to-report.php[/url]
PHP is not type strict.
------------------------------------------------------------------------
[2007-03-02 16:20:40] smlerman at gmail dot com
Description:
------------
If you try to use a boolean as an array (which most likely means an
error occurred somewhere), the value is correctly returned as NULL, but
no error message is reported. Obviously not a major problem, but it
would make debugging a little easier.
Reproduce code:
---------------
<?php
var_dump(error_reporting());
$a = false;
var_dump($a[0]);
$b = (string)$a;
var_dump($b[0]);
?>
Expected result:
----------------
int(8191)
[Something like] Notice: Cannot use boolean as array in C:\Documents
and Settings\...\boolean_array.php on line 5
NULL
Notice: Uninitialized string offset: 0 in C:\Documents and
Settings\...\boolean_array.php on line 8
string(0) ""
Actual result:
--------------
int(8191)
NULL
Notice: Uninitialized string offset: 0 in C:\Documents and
Settings\Scott\My Documents\Test Files\boolean_array.php on line 8
string(0) ""
------------------------------------------------------------------------
--
Edit this bug report at [url]http://bugs.php.net/?id=40692&edit=1[/url]
smlerman at gmail dot com Guest
-
iliaa@php.net #4
#40692 [Opn->Bgs]: Trying to use boolean as array doesn't give an error
ID: 40692
Updated by: [email]iliaa@php.net[/email]
Reported By: smlerman at gmail dot com
-Status: Open
+Status: Bogus
Bug Type: Scripting Engine problem
Operating System: Any
PHP Version: 5.2.1
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
[url]http://www.php.net/manual/[/url] and the instructions on how to report
a bug at [url]http://bugs.php.net/how-to-report.php[/url]
(string)false == ""
"" does not have offset 0 and therefor you get a warning message.
(array)false == array(0 => false);
and when you access element 0 of this array you get false in return.
Previous Comments:
------------------------------------------------------------------------
[2007-03-03 16:57:17] smlerman at gmail dot com
Yeah, in 6 years of programming PHP, I never noticed that it isn't a
strictly typed language. Trying to use an undefined offset of an array
gives an error message. Trying to use a non-existant character index of
a string gives an error message. So what is the boolean being converted
to such that using an incorrect offset isn't an error?
------------------------------------------------------------------------
[2007-03-03 15:58:22] [email]iliaa@php.net[/email]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
[url]http://www.php.net/manual/[/url] and the instructions on how to report
a bug at [url]http://bugs.php.net/how-to-report.php[/url]
PHP is not type strict.
------------------------------------------------------------------------
[2007-03-02 16:20:40] smlerman at gmail dot com
Description:
------------
If you try to use a boolean as an array (which most likely means an
error occurred somewhere), the value is correctly returned as NULL, but
no error message is reported. Obviously not a major problem, but it
would make debugging a little easier.
Reproduce code:
---------------
<?php
var_dump(error_reporting());
$a = false;
var_dump($a[0]);
$b = (string)$a;
var_dump($b[0]);
?>
Expected result:
----------------
int(8191)
[Something like] Notice: Cannot use boolean as array in C:\Documents
and Settings\...\boolean_array.php on line 5
NULL
Notice: Uninitialized string offset: 0 in C:\Documents and
Settings\...\boolean_array.php on line 8
string(0) ""
Actual result:
--------------
int(8191)
NULL
Notice: Uninitialized string offset: 0 in C:\Documents and
Settings\Scott\My Documents\Test Files\boolean_array.php on line 8
string(0) ""
------------------------------------------------------------------------
--
Edit this bug report at [url]http://bugs.php.net/?id=40692&edit=1[/url]
iliaa@php.net Guest
-
smlerman at gmail dot com #5
#40692 [Bgs->Opn]: Trying to use boolean as array doesn't give an error
ID: 40692
User updated by: smlerman at gmail dot com
Reported By: smlerman at gmail dot com
-Status: Bogus
+Status: Open
Bug Type: Scripting Engine problem
Operating System: Any
PHP Version: 5.2.1
New Comment:
Actually, as my code shows, you do not get false, you get NULL, so it's
obviously not doing a normal conversion to an array. I'm not disputing
the value of the expression, since it makes perfect sense to me that
the value of a non-existent variable should be NULL. In all other
cases, though, it also gives a notice, which is what would be nice to
have.
Previous Comments:
------------------------------------------------------------------------
[2007-03-05 00:10:28] [email]iliaa@php.net[/email]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
[url]http://www.php.net/manual/[/url] and the instructions on how to report
a bug at [url]http://bugs.php.net/how-to-report.php[/url]
(string)false == ""
"" does not have offset 0 and therefor you get a warning message.
(array)false == array(0 => false);
and when you access element 0 of this array you get false in return.
------------------------------------------------------------------------
[2007-03-03 16:57:17] smlerman at gmail dot com
Yeah, in 6 years of programming PHP, I never noticed that it isn't a
strictly typed language. Trying to use an undefined offset of an array
gives an error message. Trying to use a non-existant character index of
a string gives an error message. So what is the boolean being converted
to such that using an incorrect offset isn't an error?
------------------------------------------------------------------------
[2007-03-03 15:58:22] [email]iliaa@php.net[/email]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
[url]http://www.php.net/manual/[/url] and the instructions on how to report
a bug at [url]http://bugs.php.net/how-to-report.php[/url]
PHP is not type strict.
------------------------------------------------------------------------
[2007-03-02 16:20:40] smlerman at gmail dot com
Description:
------------
If you try to use a boolean as an array (which most likely means an
error occurred somewhere), the value is correctly returned as NULL, but
no error message is reported. Obviously not a major problem, but it
would make debugging a little easier.
Reproduce code:
---------------
<?php
var_dump(error_reporting());
$a = false;
var_dump($a[0]);
$b = (string)$a;
var_dump($b[0]);
?>
Expected result:
----------------
int(8191)
[Something like] Notice: Cannot use boolean as array in C:\Documents
and Settings\...\boolean_array.php on line 5
NULL
Notice: Uninitialized string offset: 0 in C:\Documents and
Settings\...\boolean_array.php on line 8
string(0) ""
Actual result:
--------------
int(8191)
NULL
Notice: Uninitialized string offset: 0 in C:\Documents and
Settings\Scott\My Documents\Test Files\boolean_array.php on line 8
string(0) ""
------------------------------------------------------------------------
--
Edit this bug report at [url]http://bugs.php.net/?id=40692&edit=1[/url]
smlerman at gmail dot com Guest
-
smlerman at gmail dot com #6
#40692 [Opn]: Trying to use boolean as array doesn't give an error
ID: 40692
User updated by: smlerman at gmail dot com
Reported By: smlerman at gmail dot com
Status: Open
Bug Type: Feature/Change Request
Operating System: Any
PHP Version: 5.2.1
New Comment:
Here's another test case that shows that something isn't quite right
with implicit conversions.
<?php
var_dump(error_reporting());
$a = 12345;
var_dump($a[0]); // Should cast to string or possibly array
var_dump($a{0}); // Should cast to string
$b = (string)$a;
var_dump($b[0]);
$c = (array)$a;
var_dump($c[0]);
?>
Results:
int(8191)
NULL
NULL
string(1) "1"
int(12345)
So $a isn't being converted to a string or array if you do $a[0]. It
also isn't converted to a string if you do $a{0}, and I have no idea
what else it could reasonably convert to. I never rely on these
implicit conversions, so I have no real personal interest in whether
the behavior stays the same as it is now or if the conversions are
fixed, but some kind of error message, even a notice for an undefined
index for something like $a['foo'], would help with debugging this kind
of programmer mistake.
Previous Comments:
------------------------------------------------------------------------
[2007-03-05 00:22:42] smlerman at gmail dot com
Actually, as my code shows, you do not get false, you get NULL, so it's
obviously not doing a normal conversion to an array. I'm not disputing
the value of the expression, since it makes perfect sense to me that
the value of a non-existent variable should be NULL. In all other
cases, though, it also gives a notice, which is what would be nice to
have.
------------------------------------------------------------------------
[2007-03-05 00:10:28] [email]iliaa@php.net[/email]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
[url]http://www.php.net/manual/[/url] and the instructions on how to report
a bug at [url]http://bugs.php.net/how-to-report.php[/url]
(string)false == ""
"" does not have offset 0 and therefor you get a warning message.
(array)false == array(0 => false);
and when you access element 0 of this array you get false in return.
------------------------------------------------------------------------
[2007-03-03 16:57:17] smlerman at gmail dot com
Yeah, in 6 years of programming PHP, I never noticed that it isn't a
strictly typed language. Trying to use an undefined offset of an array
gives an error message. Trying to use a non-existant character index of
a string gives an error message. So what is the boolean being converted
to such that using an incorrect offset isn't an error?
------------------------------------------------------------------------
[2007-03-03 15:58:22] [email]iliaa@php.net[/email]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
[url]http://www.php.net/manual/[/url] and the instructions on how to report
a bug at [url]http://bugs.php.net/how-to-report.php[/url]
PHP is not type strict.
------------------------------------------------------------------------
[2007-03-02 16:20:40] smlerman at gmail dot com
Description:
------------
If you try to use a boolean as an array (which most likely means an
error occurred somewhere), the value is correctly returned as NULL, but
no error message is reported. Obviously not a major problem, but it
would make debugging a little easier.
Reproduce code:
---------------
<?php
var_dump(error_reporting());
$a = false;
var_dump($a[0]);
$b = (string)$a;
var_dump($b[0]);
?>
Expected result:
----------------
int(8191)
[Something like] Notice: Cannot use boolean as array in C:\Documents
and Settings\...\boolean_array.php on line 5
NULL
Notice: Uninitialized string offset: 0 in C:\Documents and
Settings\...\boolean_array.php on line 8
string(0) ""
Actual result:
--------------
int(8191)
NULL
Notice: Uninitialized string offset: 0 in C:\Documents and
Settings\Scott\My Documents\Test Files\boolean_array.php on line 8
string(0) ""
------------------------------------------------------------------------
--
Edit this bug report at [url]http://bugs.php.net/?id=40692&edit=1[/url]
smlerman at gmail dot com Guest



Reply With Quote

