Skip to content

Commit

Permalink
Add magic methods to ADOFetchObj
Browse files Browse the repository at this point in the history
This allows hanlding of dynamic properties for PHP 8.2 compatibility,
without relying on the AllowDynamicProperties attribute.

The constructor accepts an array of (fieldname => value) pairs for easy
initialization.

Fixes #982
  • Loading branch information
dregad committed Jun 11, 2023
1 parent ea8b291 commit 8bc38a1
Showing 1 changed file with 46 additions and 8 deletions.
54 changes: 46 additions & 8 deletions adodb.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -3799,17 +3799,55 @@ protected function getChangedErrorMsg($old = null) {

} // end class ADOConnection



//==============================================================================================
// CLASS ADOFetchObj
//==============================================================================================

/**
* Internal placeholder for record objects. Used by ADORecordSet->FetchObj().
* RecordSet fields data as object.
*
* @see ADORecordSet::fetchObj(), ADORecordSet::fetchObject(),
* @see ADORecordSet::fetchNextObj(), ADORecordSet::fetchNextObject()
*/
class ADOFetchObj {
};
/** @var array The RecordSet's fields */
protected $data;

/**
* Constructor.
*
* @param array $fields Associative array with RecordSet's fields (name => value)
*/
public function __construct(array $fields = [])
{
$this->data = $fields;
}

public function __set(string $name, $value)
{
$this->data[$name] = $value;
}

public function __get(string $name)
{
if (isset($this->data[$name])) {
return $this->data[$name];
}
ADOConnection::outp("Unknown field: $name");
return null;
}

public function __isset($name)
{
return isset($this->data[$name]);
}

public function __debugInfo()
{
return $this->data;
}

public static function __set_state(array $data)
{
return new self($data['data']);
}
}

/**
* Class ADODB_Iterator_empty
Expand Down

0 comments on commit 8bc38a1

Please sign in to comment.