Skip to content

v0.8.11

Latest

Choose a tag to compare

@github-actions github-actions released this 16 Nov 19:47
Immutable release. Only release title and notes can be modified.
03cd6a6

Changed

  • deepclone_from_array() doesn't convert an object to a string anymore when
    a payload puts it in a string property: it throws a TypeError, like
    unserialize(). The conversion called __toString() on an object that
    might not be hydrated yet, and crashed on a BcMath\Number that still
    waits for its state.
  • deepclone_hydrate() doesn't create a string anymore for each key that
    names a protected or private property.
  • deepclone_to_array() evaluates the constant expressions of a class once
    per call to find the closures they declare. It did it again for each
    closure, up to its declaration, running the constructors of attribute
    arguments each time: exporting 20,000 objects that hold the same attribute
    closure took 1.6 s, and takes 8 ms now.
  • On PHP 8.5 and 8.6, ReflectionAttribute::newInstance() and
    ::getArguments() cost the same as without the extension for the
    attributes that take literals only. For the others, the extension doesn't
    build the property table of each object of the instance anymore, which
    tripled the memory they use. It also skips scalars, enum cases and literal
    arrays, and needs no table to remember the objects it went through:
    instantiating an attribute that takes two objects costs 10% more than
    without the extension, down from 37%.
  • deepclone_to_array() scans nested arrays once to tell whether they can be
    shared as is. It scanned them again at each level when one held an object:
    400 levels of 200 scalars over an object took 20 ms, and take 3 ms now.
  • deepclone_to_array() shares the state that __serialize() returns when
    it holds scalars only, like it does for the arrays of properties. It copied
    it before: one million integers took 30 ms and 17 MB.
  • deepclone_to_array() removes the scope prefix from the names of protected
    and private properties once per class, instead of once per object, and
    looks the classes it met last up by address: exporting a graph of 5,700
    objects that describe entities needs 11% fewer instructions.

Fixed

  • deepclone_to_array() crashed on a stdClass object whose property table
    has integer keys. ArrayObject writes such keys to the object it wraps.
  • deepclone_to_array() crashed when __sleep(), __serialize() or a lazy
    initializer assigned a new value to a & reference of the graph that holds
    the object being exported.
  • deepclone_to_array() stops at the exception that an error handler throws
    while it reads the state of an object. It went on before, and could replace
    the exception with a NotInstantiableException.
  • deepclone_to_array() ran the destructor of the instances it creates to
    read the default values of a class. This happened for objects that have
    dynamic properties or that were cast to array, eg by foreach, and made
    the call fail when the destructor needed what the constructor sets.
  • deepclone_to_array() merged the & references that __serialize() or
    __sleep() create and release while the graph is walked, as their addresses
    got reused: references are kept alive until the payload is built, like
    objects.
  • The cycles of objects that __serialize() creates were never collected
    when the cycle collector ran during deepclone_to_array().
  • For classes cached by OPcache, deepclone_to_array() exported the
    properties that hold a default value declared with a global constant or an
    enum case, unlike without OPcache.
  • deepclone_to_array() finds the private properties of anonymous classes
    when __sleep() returns them by their mangled name.
  • deepclone_hydrate() wrote to the property table that a stdClass object
    shares with a clone, or with the array it was cast from or to: the write
    changed them too.
  • deepclone_hydrate() and deepclone_from_array() could corrupt memory
    when the destructor of a value they replace in a stdClass object, or in a
    dynamic property bound to a reference, wrote to the same object.
  • deepclone_hydrate() wrote to the lazy proxy itself once it is initialized,
    instead of its real instance. On a lazy object that isn't initialized, the
    default flags ran set hooks, and neither converted scalars to backed enums
    nor left null properties uninitialized.
  • deepclone_hydrate() let null uninitialize a readonly property, which
    could then be written again, and bound readonly properties to references
    with DEEPCLONE_HYDRATE_PRESERVE_REFS.
  • deepclone_hydrate() loads the backed enum of a property when needed to
    convert a scalar to its case. The conversion was skipped when the enum
    wasn't loaded yet.
  • deepclone_hydrate() calls __set() for an untyped property that was
    unset, and writes through the reference that an untyped property holds,
    like ReflectionProperty::setRawValue().
  • With DEEPCLONE_HYDRATE_PRESERVE_REFS, the value of a reference is
    converted like other values: to the type of the property, to the case of a
    backed enum, and null leaves the property uninitialized.
  • With DEEPCLONE_HYDRATE_PRESERVE_REFS, binding a reference to a new dynamic
    property triggers the "Creation of dynamic property" deprecation, like
    writing a value does.
  • References bound to a typed property that a child class redeclares are
    tracked by that property. Destroying the object could corrupt memory when
    the reference was bound through the scope of the parent class.
  • deepclone_hydrate() accepts the keys that an (array) cast gives to the
    private properties of an anonymous class, whose name contains a NUL byte.
  • deepclone_hydrate() rejects mangled keys for stdClass objects, like for
    other classes: "\0*\0foo" created a public foo property.
  • $allowed_classes can hold & references, eg after a foreach by
    reference on the list, like the allowed_classes option of unserialize().
  • Called from Serializable::unserialize(), deepclone_from_array() could
    corrupt memory when the payload held an object exported as a serialized
    string: unserializing it joined the context of the outer unserialize()
    call. Such strings are now unserialized in a context of their own.
  • Called from Serializable::serialize(), deepclone_to_array() exported
    Serializable objects as back-references to the stream of the outer
    serialize() call, eg r:2;, which nothing else can restore. They're
    serialized in a context of their own too.
  • On PHP 8.4 and 8.5, deepclone_hydrate() with
    DEEPCLONE_HYDRATE_NO_LAZY_INIT could corrupt the memory of the next
    request when user code called it while the request shuts down, eg from the
    stream_close() of a stream wrapper or from the save handler of a session.
  • deepclone_from_array() built a reference that holds itself for "refs"
    that target each other with hard-reference markers in "refMasks", which
    made the first use of the result loop forever. Such a reference takes the
    value of its target now, and is rejected when it targets itself, also
    through another reference.
  • deepclone_from_array() throws when the stack limit is reached on deeply
    nested values and masks, on PHP 8.4+. It crashed before.
  • deepclone_from_array() rejects named closures over abstract methods:
    calling one crashed for the methods of internal interfaces.
  • String keys in "refs" are kept apart from reference ids. A string key
    could take the place of an id that equals its hash.
  • When deepclone_from_array() returns lazy ghosts, their properties aren't
    bound to the & references that the payload itself holds anymore, like for
    other objects.
  • On ZTS builds, first-class callables that an attribute declares over a
    method of another class, or over a function, were only exported as
    references to their declaration on the thread that started PHP. Other
    threads, ie all requests with FrankenPHP, required $allow_named_closures.
  • The class that declares such a callable was remembered for the lifetime of
    the process: a request that only loaded another class that declares the
    same callable failed.
  • A callable over a static method called on a child class, eg B::m(...),
    was exported as the self::m(...) that its parent declares in a constant
    expression, and restored as a call on the parent.
  • A closure over a method of a parent class, eg parent::m(...), was
    restored as a closure over the method that overrides it. Such closures are
    exported with the class that declares the method, like the ones over
    non-public methods.
  • exit() was ignored when called while deepclone_to_array() evaluates the
    constant expressions of a class, eg by the constructor of an attribute
    argument.
  • With the extension loaded on PHP 8.5 and 8.6,
    ReflectionAttribute::newInstance() threw an Error, or didn't return,
    when the instance holds an array that references itself.
  • When it reached the stack limit on deeply nested arrays,
    deepclone_to_array() went on level after level, each one throwing again:
    200,000 levels took 90 s and chained 16,000 errors. It throws once now.
  • deepclone_from_array() replays the states of final internal classes like
    BcMath\Number before any user code runs. A payload that orders its states
    another way than deepclone_to_array() gave such an object to the
    __unserialize() or __wakeup() of another one before it was initialized,
    and reading a BcMath\Number in that state crashes.