[prev in list] [next in list] [prev in thread] [next in thread] 

List:       php-doc-bugs
Subject:    [DOC-BUGS] #44844 [Com]: array_pop brings error message if parameter is not an array
From:       "crrodriguez at suse dot de" <doc-bugs () lists ! php ! net>
Date:       2008-04-28 5:34:35
Message-ID: 200804280534.m3S5YZE5028641 () y1 ! php ! net
[Download RAW message or body]

 ID:               44844
 Comment by:       crrodriguez at suse dot de
 Reported By:      Ultrasick at gmx dot de
 Status:           Open
 Bug Type:         Documentation problem
 Operating System: Linux
 PHP Version:      5.2.5
 New Comment:

>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


Previous Comments:
------------------------------------------------------------------------

[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.

------------------------------------------------------------------------

[2008-04-26 19:49:35] Ultrasick at gmx dot de

Description:
------------
<?
array_pop($DoesntExist);
?>

leads to:

"Warning: array_pop() [function.array-pop]: The argument should be an
array in /.../test.php on line 2"

But documentation says:

"If array is empty (or is not an array), NULL will be returned."

Reproduce code:
---------------
<?
array_pop($DoesntExist);
?>

Expected result:
----------------
should return NULL

Actual result:
--------------
"Warning: array_pop() [function.array-pop]: The argument should be an
array in /.../test.php on line 2"


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=44844&edit=1


-- 
PHP Documentation Bugs Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic