php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #52574 function in namespace - call from string
Submitted: 2010-08-10 11:51 UTC Modified: 2010-08-10 12:11 UTC
From: flyingmana at googlemail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.3.3 OS: Ubuntu
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: flyingmana at googlemail dot com
New email:
PHP Version: OS:

 

 [2010-08-10 11:51 UTC] flyingmana at googlemail dot com
Description:
------------
in a script without namespaces you could took the function name in a string und call it via $string()

this does not work, if this function is located in a namespace.


The analog case with classes is described as ok in the docs(dont have tested it), so it should also work with functions.
So i Request to add this feature.

Test script:
---------------
<?php

namespace bar{

	function foo(){
		echo "test", "\n";
	}

	function foo2(){
		echo "test2", "\n";
	}
	function foo3(){
		echo "test3", "\n";
	}
}

namespace{
	echo "start \n";
	\bar\foo();
	use \bar as haha;
	haha\foo2();
	$test = 'haha\foo3';
	$test();
}


?>

Expected result:
----------------
test
test2
test3

Actual result:
--------------
test
test2

Fatal error: Call to undefined function haha\foo3() in /home/flyingmana/Desktop/sandkasten/namespace.php on line 19


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-08-10 12:11 UTC] johannes@php.net
-Status: Open +Status: Bogus
 [2010-08-10 12:11 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
 [2010-08-10 12:50 UTC] flyingmana at googlemail dot com
Sorry, have looked multiple times to the manual and havent find where this was described for functions.
But back to the problem, i see the call from a string does work.
But if you use an namespace alias, like in my example, it does not work anymore.
Is this real not a bug?
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 15 07:01:31 2025 UTC