Tracking Object Property Changes

From: Date: Wed, 10 Mar 2021 16:10:32 +0000
Subject: Tracking Object Property Changes
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-113436@lists.php.net to get a copy of this message
Hello, Joseph! I faced exactly the same problems and believe that the Observer API is necessary.

To solve a similar problem, I implemented my own API over FFI, however, it does not work very stable (I have little experience in send api), but it may help to solve your problems: https://github.com/SerafimArts/Observer

09.03.2021 5:32, Joseph Montanez пишет:
I am not sure what to title this but the gist is that I have two structs with a one way dependency: // Vector3 type typedef struct Vector3 {
     float x;
     float y;
     float z;
} Vector3; // Ray type (useful for raycast) typedef struct Ray {
     Vector3 position;       // Ray position (origin)
     Vector3 direction;      // Ray direction
} Ray; I've gone ahead and made a test extension here: https://github.com/joseph-montanez/php-ext-reference-issue . I've made each struct a PHP object. allowing me to do this: <?php $position = new \skeleton\Vector3(1,2,3); $direction = new \skeleton\Vector3(4,5,6); $ray = new \skeleton\Ray($position, $direction); echo 'Z: ', $ray->position->z, PHP_EOL; // Outputs: 3 $position->z = 9; echo 'Z: ', $ray->position->z, PHP_EOL; // Outputs: 9 The PHP Ray object is defined as so: typedef struct _skeleton_ray_object {
     Ray ray;
     HashTable *prop_handler;
     zend_object std;
     skeleton_vector3_object *position;
     skeleton_vector3_object *direction;
} skeleton_ray_object; When I update either vector3 object, I don't have a way to propagate the changes back to the parent object(Ray). This means the raw Ray struct is never updated. Is there a built-in way to handle propagation (listeners) in a PHP extension or will I need to hand roll this? Thanks, Joseph Montanez


Thread (5 messages)

« previous php.internals (#113436) next »