Description
Example documentation in README demonstrates an array object:
$session = $manager->getCurrentSession();
$session["foo"] = "bar";
unset($session["bar"]);
This is obsolete as it uses magic methods for dynamic properties and does not extend the \ArrayObject class:
class Session implements \Countable {
// ...
public function __get(string $name)
public function __set(string $name, $value): void
// ...
}
What direction would you like to take?
My opinion is to go for all these:
- extend \ArrayObject (and throw an exception for non-existing variables like a normal array)
- add a
get($variable, $default = null);
andset($variable, $value);
method as alternate syntax - keep dynamic properties using magic methods
__get()
and__set()
(current) but change__get()
to throw an exception instead of returning null as it goes against normal dynamic property usage
The reason I suggest partially moving away from dynamic properties is because it behaves totally different from $_SESSION which is what many people are used to, and because they are becoming deprecated in 8.2. However, the magic __get()
and __set()
methods will not be deprecated, but I personally think people will start to move away from using dynamic properties in general. Which would make this library use/force an old syntax in a way.
Reason I would still include dynamic properties is for backwards compatibility and for people who really like using it like this.
Let me know. I don't mind working on it and have the time. (I have my own session library which extends ArrayObject but isn't native like this one, so it wouldn't be too much work for me)