Skip to content

Instantly share code, notes, and snippets.

function findProperties(elem) {
let result = [];
for(let prop in elem) {
if(elem.hasOwnProperty(prop)) {
result.push(prop);
}
}
return result;
}
@serious-scribbler
serious-scribbler / DynamicProperties.php
Created December 16, 2022 07:06
Dynamic Properties in PHP 8.2
<?php
class Dynamique {
private array $dynamic = [];
public function __set(string $name, mixed $value) {
echo "set $name to $value\n";
if(property_exists($this, $name)) {
$this->{$name} = $value;
} else {
$this->dynamic[$name] = $value;