Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reflection class PHP from file?

I wanna get value from Class PHP without initialize this Class. For this I give the file path where this class, for it to be reviewed, but not initialized.

My Idea:

<?php
$reflection = new ReflectionClass( '/var/www/classes/Base.php' );
$version = $reflection->getProperty('version')->getValue(  );

if( $version >= 1 )
{
    return true;
}
return false;
?>

BASE.PHP

<?php
class Base
{
    private $version = 2;
}
?>
like image 681
Jorge Olaf Avatar asked Nov 03 '22 21:11

Jorge Olaf


1 Answers

whats about static? its much simpler:

<?php
class Base
{
    public static $version = 2; // or $version = array(1,2,3);
}

if(is_array(Base::$version)) {
    print_r(Base::$version);
} else {
    echo Base::$version;
}

?>
like image 50
steven Avatar answered Nov 09 '22 15:11

steven