Hi Elijah, On Tue, Dec 29, 2015 at 12:47 AM, Elijah Johnson <ejrx7...@gmail.com> wrote: > The mode "stack-mode-static-object-types" would ideally also prevent > assignment of an object with a current string value, or string placeholder > value. What I mean by placeholder value - an additional z-val type "t" > returning true for IS_NULL, where the class name id is stored in value > union. This would be declared by type hint ex. MyObject $object; If the > variable is assigned, MyObject $object = ...; then potentially the same. > > On assignment would look something like this (pseudo-code): > > bool checkType(zVal, newZVal) > { > bool throw_error = false; > if (MODE_STACK_TYPE_OBJECT) > { > if (isObjectType(zVal)) > { > int class_id= GET_PLACEHOLDER_CLASS(zVal);// ie. > zVal.value or value of current object > if (class_id !== GET_CLASS(newZVal)) > { > throw_error = true; > } > } else if (IS_OBJECT(newZVal) && !IS_NULL(zVal){ > throw_error = true; // assigning an object to a non-null, > non-object > } > } > if (throw_error) > { > // assign to null, generate TypeError > // ie. Warning: assign of type to type, assigned null value > return false; // prevent assignment by caller > } > return true > } > > Some additional checks would likely be necessary to prevent placeholders > from being assigned and returned, and if strict mode was implemented, there > would need to be a second placeholder type (or some other means of > identification such as a constant). > > Implementing placeholders isn't a necessary step, but it would make for > very readable code.
Now I understand why you think zval modification is needed and concern about performance. My proposal checks basic types simply. i.e. Only checks if a variable is object type or not. Simple and quick. Object(class) is type, so it makes sense checking class consistency. If we check object's class, not only the class but also ancestor classes should be checked. This may affect performance. I'm not sure if this worth the effort. Regards, -- Yasuo Ohgaki yohg...@ohgaki.net -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php