Re: Re: com php-src: Add optional second arg to unserialize(): ext/standard/basic_functions.c
ext/standard/tests/serialize/serialization_error_001.phpt ext/standard/tests/serialize/unserialize_consumed.phpt ext/standard/var.c
| From: | Sara Golemon | Date: | Tue, 10 Jun 2014 17:02:42 +0000 |
| Subject: | Re: Re: com php-src: Add optional second arg to unserialize(): ext/standard/basic_functions.c ext/standard/tests/serialize/serialization_error_001.phpt ext/standard/tests/serialize/unserialize_consumed.phpt ext/standard/var.c |
||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-74823@lists.php.net to get a copy of this message | ||
SPLDoublyLinkedList's format was just the original wtf moment which
caught my attention. I went with the change to unserialize() because
that gives more power to the user. If you don't like that simple
approach, we could always introduce a new construct entirely, say
something like the following (note that I haven't given deep thought
to this API, it's just off the cuff):
class PhpUnserializer {
public function __construct(string $str): void;
/* advanced APIs for this kind of case */
public function isValid(): bool; // whole string was parsable serialize data
public function getErrorOffset(): int; // Where unserialize stopped parsing
/* Basic APIs for common cases */
public static function unserialize(string $str): mixed;
public function isScalar(): bool;
public function size(): int;
/* Maybe implement Iterator in some clever way to avoid unserializing
* the entire string at once? */
/* Override in child class for autoload/filter classes as they're
implemented */
public function getClass(string $class, mixed $data): ?object {
/* Base implementation instantiates $class and unserializes it with $data
* Children could add logic like:
* if ($class != 'stdClass') throw new Exception("Eff Off");
* else return parent::getObject($class, $data);
*/
}
}