php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34244 The array_pop()-function doesn't take immediate arrays (like explode())
Submitted: 2005-08-25 02:58 UTC Modified: 2005-08-25 08:09 UTC
Votes:2
Avg. Score:3.0 ± 2.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: d-tail at msx dot org Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.1.0RC1 OS: Windows XP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: d-tail at msx dot org
New email:
PHP Version: OS:

 

 [2005-08-25 02:58 UTC] d-tail at msx dot org
Description:
------------
The array_pop()-function (and most likely, similar array operators) doesn't take immediate arrays anymore, that is, arrays without a variable name. It worked in previous versions, though.

Reproduce code:
---------------
<?php
  $bread = "slice1.slice2.slice3.slice4";
  $last_slice = array_pop(explode(".", $bread));
  echo($last_slice);
?>


Expected result:
----------------
Expect to see: "slice4"

Workaround:
<?php
  $bread = "slice1.slice2.slice3.slice4";
  $slices_array = explode(".", $bread);
  $last_slice = array_pop($slices_array);
  echo($last_slice);
?>

Actual result:
--------------
Fatal error: Only variables can be passed by reference in D:\www\browser\index.php on line 46

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-08-25 03:16 UTC] d-tail at msx dot org
Another workaround is this:
<?php
  $bread = "slice1.slice2.slice3.slice4";
  $last_slice = array_pop(@explode(".", $bread));
  echo($last_slice);
?>

Notice the '@' before the explode()-function.
 [2005-08-25 08:09 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Mon Mar 30 13:01:25 2020 UTC