php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #34124 array_push() fails when the array doesn't exist
Submitted: 2005-08-13 15:14 UTC Modified: 2005-08-14 00:40 UTC
From: ondrej at sury dot org Assigned: sean (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.0.4 OS: Linux
Private report: No CVE-ID: None
 [2005-08-13 15:14 UTC] ondrej at sury dot org
Description:
------------
From http://bugs.debian.org/289244:

array_push will not create new array when called with arg which is not array type (or nonexistant).

This could be just documentation error to state, that new array won't be created inside array_push().

I am not sure that there is easy fix inside PHP, since array parameter in array_push is reference and not value.  So it looks like that it gets created inside array_push, but discarded (or leaked?) afterwards.

Reproduce code:
---------------
<?php
array_push ($foo, 1, 2, 3);
print ("bar $foo[0] baz\n");
?>


Expected result:
----------------
bar 1 baz

Actual result:
--------------
bar  baz

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-08-13 15:19 UTC] tony2001@php.net
Ever tried to set display_errors to On and error_reporting to E_ALL ?

This is what your code outputs.:
Warning: array_push(): First argument should be an array in ..

I don't see any bugs here.
 [2005-08-13 15:31 UTC] ondrej at sury dot org
As I stated in original bug report, it could be just lack of note in docs.

I guess that problem original submitter had was, that it's pretty normal that variables in PHP can be used without initialization, it prints WARNING, but in the end it works as expected.  Also documentation states that array_push has same effect as $array[] = $var, which is not true, because [] statement creates array.


So I guess simple adding:

"NOTE: array_push will not create array when called with non-array argument."

to docs won't hurt.  And it could avoid confusion on user side.
 [2005-08-13 20:55 UTC] derick@php.net
Ifit's a documentation problem... make sure you set the category to "Documentation problem" then...
 [2005-08-13 21:06 UTC] sean@php.net
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.


 [2005-08-14 00:40 UTC] ondrej at sury dot org
I was just not sure, what's upstream policy on these kind of bugs.  Now I know, so next bugs will be better :-).

Thanks for fix.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 16:01:27 2024 UTC