I'd like to know if there is any way to prevent the use of trait methods out of any class context in PHP ?
Let me explain what I want with a short example, here is my current code :
// File : MyFunctions.php
trait MyFunctions {
function hello_world() {
echo 'Hello World !';
}
}
// File : A.php
include 'MyFunctions.php';
class A {
use MyFunctions;
}
// File : testTraits.php
include 'A.php';
hello_world(); // Call to undefined function -> OK, expected
A::hello_world(); // Hello World ! -> OK, expected
MyFunctions::hello_world(); // Hello World ! -> Maybe OK, but not expected, I'd like to prevent it
PHP manual page about traits is very comprehensive, and a lot of cases are treated, but not this one (http://php.net/manual/en/language.oop5.traits.php)
I desperatly tried to remove "static" and use "public", "protected", "private", but of course, it just didn't work. I've no other ideas so far, so maybe I'm missing something, or it's just impossible ?
use Trait { hello_world as public hello_world; }to make it public inClassWithTrait?