From 8d6f5f4656041932cccf67b9c04a045193c264a7 Mon Sep 17 00:00:00 2001 From: David Cole Date: Sat, 25 Sep 2021 02:08:36 +1200 Subject: [PATCH] Fix read property `rv` segfault --- example/skel/test.php | 17 +++-------------- src/php/types/object.rs | 4 ++++ 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/example/skel/test.php b/example/skel/test.php index cf76234230..afeb86eb69 100644 --- a/example/skel/test.php +++ b/example/skel/test.php @@ -1,16 +1,5 @@ 'world']); -//include 'vendor/autoload.php'; - -//$ext = new ReflectionExtension('skel'); - -//dd($ext); - -//$x = fn_once(); -//$x(); -//$x(); - -//// $x = get_closure(); - -//// var_dump($x(5)); +$x = new TestClass; +var_dump($x); +var_dump($x->b); diff --git a/src/php/types/object.rs b/src/php/types/object.rs index ecc88721ae..a6cefc44b9 100644 --- a/src/php/types/object.rs +++ b/src/php/types/object.rs @@ -27,6 +27,7 @@ use crate::{ class::ClassEntry, enums::DataType, exceptions::PhpException, + flags::ZvalTypeFlags, types::{array::OwnedHashTable, string::ZendString}, }, }; @@ -659,7 +660,10 @@ impl ZendObjectHandlers { let self_ = obj.obj.assume_init_mut(); let mut props = T::get_properties(); let prop = props.remove(prop_name.as_str().ok_or("Invalid property name given")?); + + // retval needs to be treated as initialized, so we set the type to null let rv_mut = rv.as_mut().ok_or("Invalid return zval given")?; + rv_mut.u1.type_info = ZvalTypeFlags::Null.bits(); Ok(match prop { Some(prop) => {