Skip to content

Commit

Permalink
Handle deprecation of dynamic properties in PHP8.2+
Browse files Browse the repository at this point in the history
  • Loading branch information
xtophe38 committed Aug 22, 2024
1 parent 1f424c0 commit 8bd53a9
Show file tree
Hide file tree
Showing 4 changed files with 3,642 additions and 3,618 deletions.
21 changes: 11 additions & 10 deletions library/Vmwarephp/ManagedObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
class ManagedObject {
private $reference;
protected $vmwareService;
private array $aProperties = [];

function __construct(Service $vmwareService, \ManagedObjectReference $managedObjectReference) {
$this->vmwareService = $vmwareService;
Expand All @@ -14,17 +15,17 @@ function getParentHost() {
return $this->vmwareService->getVhostHost();
}

function __get($propertyName) {
if (!isset($this->$propertyName)) {
$queryForProperty = 'get' . ucfirst($propertyName);
return $this->$queryForProperty();
}
return $this->$propertyName;
}
function __get($propertyName) {
if (!array_key_exists($propertyName, $this->aProperties)) {
$queryForProperty = 'get' . ucfirst($propertyName);
return $this->$queryForProperty();
}
return $this->aProperties[$propertyName];
}

function __set($propertyName, $propertyValue) {
$this->$propertyName = $propertyValue;
}
function __set($propertyName, $propertyValue) {
$this->aProperties[$propertyName] = $propertyValue;
}

function getReferenceType() {
return $this->reference->type;
Expand Down
9 changes: 9 additions & 0 deletions library/Vmwarephp/SoapClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
namespace Vmwarephp;

class SoapClient extends \SoapClient {
private array $aProperties = [];

public function __set(string $name, mixed $value): void {
$this->aProperties[$name] = $value;
}

public function __get(string $name): mixed {
return (array_key_exists($name, $this->aProperties) ? $this->aProperties[$name]: null);
}

function __doRequest($request, $location, $action, $version, $one_way = 0) {
$request = $this->appendXsiTypeForExtendedDatastructures($request);
Expand Down
Loading

0 comments on commit 8bd53a9

Please sign in to comment.