Reputation: 5238
I'm trying to use class_alias on a facade \Facades\Security.
I tried this:
class_alias("\\Facades\\Security", "Security");
echo Security::Unique();
But i got an error (Class 'Security' not found in...).
The weird thing is that when i try this:
$facade = "Security";
class_alias("\\Facades\\" . $facade, $facade);
echo $facade::Unique();
It does work and i get an output from the function 'Unique'. So somehow storing the name of the facade in a variable and accessing it from there, fixes the problem...
Can someone tell me why?
Thanks :)
Upvotes: 0
Views: 1031
Reputation: 12117
Suppose you are using namespace
of class name.., so no need escape (\
), try this code
class_alias("\Facades\Security", "Security");
echo Security::Unique();
You will also need to add namespace
in alias class B
, see sample code
<?php
namespace Facades;
class Security {
public static function Unique(){
return "Test return";
}
}
class_alias("\Facades\Security", "\Facades\B");
echo B::Unique();
?>
Upvotes: 1