dsfhd78978
dsfhd78978
2017-01-09 05:10

如何为Scope Resolution Operator提供常规变量

已采纳
$version = \jamesiarmes\PhpEws\Client::$ews_version;

Throws

Uncaught Error: Access to undeclared static property:

Where $ews_version is a client provided variable with possible values of:

$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';

Providing const manually, works fine:

$version = \jamesiarmes\PhpEws\Client::VERSION_2013_SP1;

Please help. Thanks.

Code:

$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);
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • dpcyx08288 dpcyx08288 4年前

    I think you are trying to access a constant using a variable.

    You can solve this using reflection:

    $ews_version = 'VERSION_2007';
    $ref = new ReflectionClass(\jamesiarmes\PhpEws\Client::class);
    $version = $ref->getConstant($ews_version);
    
    点赞 评论 复制链接分享