0
$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);
Alex G
  • 3,048
  • 10
  • 39
  • 78
  • Where in the [source code](https://github.com/jamesiarmes/php-ews/blob/master/src/Client.php) do you see that variable defined publically and statically? It's not there, just like the error said. – Rafael Jan 09 '17 at 05:19
  • Why do I need to define is as static or public? It's a regular variable outside of any classes or functions. Please see my edit – Alex G Jan 09 '17 at 05:23
  • The Client Class defines a `$version` variable that is `protected`, which means you can't access it in this case. It's also an instance variable and not defined statically, so you can't access it the way you are trying. If you want to get the version of the client, you will have to modify that class to have a public getVersion function that returns this variable. – Rafael Jan 09 '17 at 05:25
  • What are my options? – Alex G Jan 09 '17 at 05:27
  • 1
    https://github.com/jamesiarmes/php-ews/pull/380 – Rafael Jan 09 '17 at 05:33

1 Answers1

2

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);
RobinvdA
  • 1,313
  • 2
  • 13
  • 28