0 - Cannot access property started with '\0' while accessing product page

Started by goudmahendra, May 02, 2017, 15:39:54 PM

Previous topic - Next topic

Milbo

Quote from: Milbo on May 25, 2017, 09:50:53 AM
But we could extend and write
if (empty($k) or strpos($k, "\0")===0) continue;

I just need to know if this construction removes the bug in php7. Your explanation support my idea :-) I like it more than the other. Jumbos idea has the disadvantage, that you cannot inherit values to children, which do not exist for the parent.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Jumbo!

You can not inherit private and protected properties of parent products to children using get_object_vars() in any PHP version.

strpos($k, "\0")===0 check looks bit odd and hard coded to me.

It is better to ensure that we are inheriting to the public properties of the parent.

if(!property_exists($parentProduct, $k)) continue;

Here is a function which ensure correct conversions of object to array if you need to inherit every properties of the object.

function object_to_array($object)
{
$reflectionClass = new ReflectionClass(get_class($object));
$array = array();

foreach ($reflectionClass->getProperties() as $property)
{
$property->setAccessible(true);
$array[$property->getName()] = $property->getValue($object);
$property->setAccessible(false);
}

return $array;
}


But this is probably little too much considering the requirement we have here.

Milbo

Quote from: Jumbo! on May 26, 2017, 10:09:32 AM
You can not inherit private and protected properties of parent products to children using get_object_vars() in any PHP version.
It is anyway not intended. The version below php7 handles it different. There was no problem before.

Quote from: Jumbo! on May 26, 2017, 10:09:32 AM
strpos($k, "\0")===0 check looks bit odd and hard coded to me.
Imho the way you suggest yourself a time ago and I think I used it, because I found it on some php official page.

Quote from: Jumbo! on May 26, 2017, 10:09:32 AM
It is better to ensure that we are inheriting to the public properties of the parent.

if(!property_exists($parentProduct, $k)) continue;

Here is a function which ensure correct conversions of object to array if you need to inherit every properties of the object.

function object_to_array($object)
{
$reflectionClass = new ReflectionClass(get_class($object));
$array = array();

foreach ($reflectionClass->getProperties() as $property)
{
$property->setAccessible(true);
$array[$property->getName()] = $property->getValue($object);
$property->setAccessible(false);
}

return $array;
}


But this is probably little too much considering the requirement we have here.

Maybe not bad as general function, but I wonder about the $property->setAccessible(true); I would do a check if it is accessible, or?
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Milbo

Quote from: Jumbo! on May 26, 2017, 10:09:32 AM
You can not inherit private and protected properties of parent products to children using get_object_vars() in any PHP version.

strpos($k, "\0")===0 check looks bit odd and hard coded to me.

It is better to ensure that we are inheriting to the public properties of the parent.

if(!property_exists($parentProduct, $k)) continue;



foreach ($attribs as $k=> $v) {
if (!property_exists($parentProduct, $k)) continue;
if ('product_in_stock' != $k and 'product_ordered' != $k) {// Do not copy parent stock into child
if (strpos ($k, '_') !== 0 and empty($child->$k)) {
$child->$k = $v;
// vmdebug($child->product_parent_id.' $child->$k',$child->$k);
}
}
}
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/