php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47235 preg_replace_callback calling a __call returns incorrect values
Submitted: 2009-01-29 02:26 UTC Modified: 2009-01-29 02:34 UTC
From: dmsuperman at gmail dot com Assigned:
Status: Closed Package: *Regular Expressions
PHP Version: 5.2.8 OS: Linux Ubuntu
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: dmsuperman at gmail dot com
New email:
PHP Version: OS:

 

 [2009-01-29 02:26 UTC] dmsuperman at gmail dot com
Description:
------------
When combining the use of preg_replace_callback with the __call automagic function, the value returned to the automagic __call function differs from the expected value. It's always wrapped in a single-element single-dimensional array (from what I can tell).

The example code with varied results can describe what I mean perfectly.

This happens in 5.2.6 and 5.2.8 (I just downloaded the latest version before testing this bug to be sure).

Reproduce code:
---------------
<?php
class my {
	function doit(){
		preg_replace_callback("/(.+)/", "var_dump", "aa");
		preg_replace_callback("/(.+)/", array($this, "output"), "aa");
		preg_replace_callback("/(.+)/", array($this, "somefunc"), "aa");
	}

	function output($arg){
		var_dump($arg);
	}

	function __call($func, $arg){
		var_dump($arg);
	}
}
$obj = new my();
$obj->doit();
?>

Expected result:
----------------
array(2) {
  [0]=>
  string(2) "aa"
  [1]=>
  string(2) "aa"
}
array(2) {
  [0]=>
  string(2) "aa"
  [1]=>
  string(2) "aa"
}
array(2) {
  [0]=>
  string(2) "aa"
  [1]=>
  string(2) "aa"
}

Actual result:
--------------
array(2) {
  [0]=>
  string(2) "aa"
  [1]=>
  string(2) "aa"
}
array(2) {
  [0]=>
  string(2) "aa"
  [1]=>
  string(2) "aa"
}
array(1) {
  [0]=>
  array(2) {
    [0]=>
    string(2) "aa"
    [1]=>
    string(2) "aa"
  }
}

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-01-29 02:34 UTC] dmsuperman at gmail dot com
I'm an idiot, I forgot __call recieved an _array_ of arguments. Ignore this, sorry guys
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 12 10:01:26 2024 UTC