GTS Joe GTS Joe - 1 year ago 69
PHP Question

PHP Trying to Use a Namespaced Function (Not Class)

I'm running PHP 5.6.24 and as far as I understand, I should be able to do this:


namespace lib;

function test_function ($var) {
echo $var;


require 'functions.php';

use lib\test_function;

test_function('Hello, world!');

However, I get a Fatal error: Call to undefined function test_function()

What am I doing wrong?

Answer Source

If you would like to use a function, you have to do something like this:

use function lib\test_function as func;
func("Hello World!");

Hope this helps!

Supporting Link!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download