php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54509 array_map fails with namespaces
Submitted: 2011-04-11 20:19 UTC Modified: 2011-04-13 11:54 UTC
From: alex at myrockgroup dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.3SVN-2011-04-11 (SVN) OS: Ubuntu 10.10
Private report: No CVE-ID: None
 [2011-04-11 20:19 UTC] alex at myrockgroup dot com
Description:
------------
Using php 5.3.3-1 array_map needs to have the namespace included in the callback despite being called from within the same namespace.

This came up with OAuth.php. Example:

Test script:
---------------
namespace mynamespace;

class OAuthUtil {/*{{{*/
  public static function urlencode_rfc3986($input) {/*{{{*/
	if (is_array($input)) {
		return array_map(array('OAuthUtil','urlencode_rfc3986'), $input);
	} else if (is_scalar($input)) {
		return str_replace('+', ' ',
	                       str_replace('%7E', '~', rawurlencode($input)));
	} else {
		return '';
	}
  }/*}}}*/
}

Expected result:
----------------
It should work the same as if the namespace were specified in the callback, but it doesn't:

namespace mynamespace;

class OAuthUtil {/*{{{*/
  public static function urlencode_rfc3986($input) {/*{{{*/
	if (is_array($input)) {
		return array_map(array('\mynamespace\OAuthUtil','urlencode_rfc3986'), $input);
	} else if (is_scalar($input)) {
		return str_replace('+', ' ',
	                       str_replace('%7E', '~', rawurlencode($input)));
	} else {
		return '';
	}
  }/*}}}*/
}

Actual result:
--------------
It does not find the function that it should.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-04-13 11:54 UTC] johannes@php.net
-Status: Open +Status: Bogus
 [2011-04-13 11:54 UTC] johannes@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

http://php.net/manual/en/language.namespaces.dynamic.php
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 09:01:29 2024 UTC