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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
49 - 34 = ?
Subscribe to this entry?

 
 [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-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 11:01:27 2024 UTC