Skip to content

Error: Cannot write property #28

Closed
@RV7PR

Description

@RV7PR

I have a class that extends mysqli class and those properties are defined as public but are actually read only properties so I have to put $property->setValue() and $property->getValue() inside a try and catch block for it to work.

Example:

do{
    foreach ($reflection->getProperties() as $property){
        if($property->isStatic()){
            continue;
        }
        $property->setAccessible(true);
        $value = $property->getValue($instance);
        if(is_array($value) || is_object($value)){
            $this->mapByReference($value);
        }

        try {
            $property->setValue($data, $value);
        }
        catch(\Exception $e) {}
        catch(\Throwable $e) {}
    }
} while($reflection = $reflection->getParentClass());

and

do{
    if(!$reflection->isUserDefined()){
        break;
    }
    foreach ($reflection->getProperties() as $property){
        if($property->isStatic()){
            continue;
        }
        $property->setAccessible(true);

        try {
            $item = $property->getValue($data);
        } catch(\Exception $e) {
            continue;
        } catch(\Throwable $e) {
            continue;
        }

        if ($item instanceof SerializableClosure || ($item instanceof SelfReference && $item->hash === $this->code['self'])) {
            $this->code['objects'][] = array(
                'instance' => $data,
                'property' => $property,
                'object' => $item instanceof SelfReference ? $this : $item,
            );
        } elseif (is_array($item) || is_object($item)) {
            $this->mapPointers($item);
            $property->setValue($data, $item);
        }
    }
} while($reflection = $reflection->getParentClass());

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions