I store a PHP Class name with the namespace as a string, in my database. Example: "App\Fields\TextField"
. Later on, based on that string, I want to read a static variable on the class, that the string defines. How could I do that?
You could actually just reach your variable like this:
namespace Foo;
class Test {
public static $foo = "BAR";
}
$string = "Foo\Test";
var_dump($string::$foo); // Output: BAR
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