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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 00:01:35 2025 UTC