Hello,
I am running into an issue with tracking PHP Objects in an internal
object. In PHP only code if you override a variable passed into an
object, the origin passed value should remain the same if the variable
is changed outside of it.
$position = new Vector3(4.0, 2.0, 4.0);
$camera = new Camera3D($position);
$position = 3; //-- Reassign the position to a new type
//-- Now the original value passed is modified, but the value in
camera should not be changed
var_dump(
$camera->position->x, //expected: 4, actual: 1.2621135907985048E-34
$camera->position->y, //expected: 2, actual: 1.401298464324817E-45
$camera->position->z //expected: 4, actual: 4
);
In C I am tracking the Objects by their own structs:
typedef struct _php_raylib_camera3d_object {
Camera3D camera3d;
HashTable *prop_handler;
php_raylib_vector3_object *position;
php_raylib_vector3_object *target;
php_raylib_vector3_object *up;
zend_object std;
} php_raylib_camera3d_object;
Position Getter
static zend_object *
php_raylib_camera3d_get_position(php_raylib_camera3d_object obj) /
{{{ /
{
GC_ADDREF(&obj->position->std);
return &obj->position->std;
}
/ }}} */
Position Setter
static int php_raylib_camera3d_set_position(php_raylib_camera3d_object
*obj, zval newval) / {{{ */
{
int ret = SUCCESS;
if (Z_TYPE_P(newval) == IS_NULL) {
// Cannot set this to null...
return ret;
}
php_raylib_vector3_object *phpPosition = Z_VECTOR3_OBJ_P(newval);
GC_ADDREF(&phpPosition->std);
GC_DELREF(&obj->position->std);
obj->position = phpPosition;
return ret;
}
/* }}} */
They are registered as a property i.e:
php_raylib_camera3d_register_prop_handler(&php_raylib_camera3d_prop_handlers,
"position", php_raylib_camera3d_get_position,
php_raylib_camera3d_set_position, NULL, NULL, NULL, NULL);
I also tried switching to tracking zend_object as well but it's the
same problem. Should I be tracking other php objects as a zval
instead?
Thanks,
Joseph Montanez