如何向范围解析运算符提供常规变量
How to provide regular variable to Scope Resolution Operator
$version = \jamesiarmes\PhpEws\Client::$ews_version;
投掷
Uncaught Error: Access to undeclared static property:
其中 $ews_version
是客户端提供的变量,可能的值为:
$ews_version = 'VERSION_2007';
$ews_version = 'VERSION_2007_SP1';
$ews_version = 'VERSION_2009';
$ews_version = 'VERSION_2010';
$ews_version = 'VERSION_2010_SP1';
$ews_version = 'VERSION_2010_SP2';
$ews_version = 'VERSION_2013';
$ews_version = 'VERSION_2013_SP1';
$ews_version = 'VERSION_2016';
手动提供 const,工作正常:
$version = \jamesiarmes\PhpEws\Client::VERSION_2013_SP1;
请帮忙。谢谢。
代码:
$ews_version = $_REQUEST['version']; // User posted version (i.e. VERSION_2009)
// Set connection information.
$host = $ews_host;
$username = $ews_username;
$password = $ews_password;
$version = \jamesiarmes\PhpEws\Client::$ews_version;
$client = new \jamesiarmes\PhpEws\Client($host, $username, $password, $version);
我认为您正在尝试使用变量访问常量。
你可以使用反射解决这个问题:
$ews_version = 'VERSION_2007';
$ref = new ReflectionClass(\jamesiarmes\PhpEws\Client::class);
$version = $ref->getConstant($ews_version);
$version = \jamesiarmes\PhpEws\Client::$ews_version;
投掷
Uncaught Error: Access to undeclared static property:
其中 $ews_version
是客户端提供的变量,可能的值为:
$ews_version = 'VERSION_2007';
$ews_version = 'VERSION_2007_SP1';
$ews_version = 'VERSION_2009';
$ews_version = 'VERSION_2010';
$ews_version = 'VERSION_2010_SP1';
$ews_version = 'VERSION_2010_SP2';
$ews_version = 'VERSION_2013';
$ews_version = 'VERSION_2013_SP1';
$ews_version = 'VERSION_2016';
手动提供 const,工作正常:
$version = \jamesiarmes\PhpEws\Client::VERSION_2013_SP1;
请帮忙。谢谢。
代码:
$ews_version = $_REQUEST['version']; // User posted version (i.e. VERSION_2009)
// Set connection information.
$host = $ews_host;
$username = $ews_username;
$password = $ews_password;
$version = \jamesiarmes\PhpEws\Client::$ews_version;
$client = new \jamesiarmes\PhpEws\Client($host, $username, $password, $version);
我认为您正在尝试使用变量访问常量。
你可以使用反射解决这个问题:
$ews_version = 'VERSION_2007';
$ref = new ReflectionClass(\jamesiarmes\PhpEws\Client::class);
$version = $ref->getConstant($ews_version);