#44844 [Opn->Csd]: array_pop brings error message if parameter is not an array
| From: | fa@php.net | Date: | Fri, 02 May 2008 21:25:37 +0000 |
| Subject: | #44844 [Opn->Csd]: array_pop brings error message if parameter is not an array | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-776@lists.php.net to get a copy of this message | ||
ID: 44844
Updated by: fa@php.net
Reported By: Ultrasick at gmx dot de
-Status: Open
+Status: Closed
Bug Type: Documentation problem
Operating System: Linux
PHP Version: 5.2.5
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-04-28 16:22:52] Ultrasick at gmx dot de
I see. If I am right the each() function does also emit a warning
message if you pass the "$DoesntExist" as the parameter. So even if I am
not happy with that it is at least uniform in php.
------------------------------------------------------------------------
[2008-04-28 05:34:34] crrodriguez at suse dot de
>It should bring a warning message if the parameter is a variable but
>not
>an array and not an unset array (like the $DoesntExist parameter).
No, if $DoesntExist is not declared then it is NULL, PHP does NOT
enforce variable declaration. and array_pop(NULL) obviously has to emit
a warning because NULL ==! array ;-)
[quote]
If you use the array_pop command in a loop like this:
<?
$Objects[] = 'foo';
$Objects[] = 'bar';
$Objects[] = 'foobar';
while($Object = array_pop($Objects)){
# ...
}
?>
[quote]
of course that code wont emit a warning at all, and that is expected.
when you do
$Objects[] = 'foo';
$Objects is being initialized and one element, with key '0' and value
'foo' is added, nothing surprising at all...
This is only a documentation problem
------------------------------------------------------------------------
[2008-04-27 07:47:56] Ultrasick at gmx dot de
It should bring a warning message if the parameter is a variable but
not an array and not an unset array (like the $DoesntExist parameter).
------------------------------------------------------------------------
[2008-04-27 07:43:22] Ultrasick at gmx dot de
If you use the array_pop command in a loop like this:
<?
$Objects[] = 'foo';
$Objects[] = 'bar';
$Objects[] = 'foobar';
while($Object = array_pop($Objects)){
# ...
}
?>
It wouldn't emit a warning message. The difference between an "empty
array" and an array which doesn't exist is so minimal. In my opinion
there is no good reason why the first case shouldn't emit a warning
while the second does.
But yes, it's true. The loop actually stops because when the warning is
emited NULL is beeing returned. It shouldn't be that php usually is set
to generate a warning message and the user has to throw away the warning
message again (@array_pop).
------------------------------------------------------------------------
[2008-04-27 02:04:42] crrodriguez at suse dot de
This is a docu problem, fails to mention that the that the function
emits a warning
BTW.. it does return NULL, there is no problem with that.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/44844
--
Edit this bug report at http://bugs.php.net/?id=44844&edit=1