Is there a way to get a PHP namespace to allow for calling functions within a namespace as if they were global?
Example:
handle()
Rather than:
prggmr\handle()
Here is my example code:
<?php
require_once 'prggmr/src/prggmr.php';
prggmr\handle(function() {
echo 'This is a test scenario';
}, 'test');
prggmr\signal('test');
Aliasing does not work for functions:
<?php
require 'prggmr/src/prggmr.php';
use prggmr\handle;
handle(function(){
echo "Test";
}, "test");
Results:
Fatal error: Call to undefined function handle()
From my understanding this excerpt from the documentation says it's not possible ...
Neither functions nor constants can be imported via the use statement.
Source:
http://www.php.net/manual/en/language.namespaces.faq.php#language.namespaces.faq.nofuncconstantuse
Not for a whole namespace, no. But for single names, you can do
use p\handle;
which aliases p\handle
to just handle
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With