Skip to content

Commit

Permalink
Fix #75607 - Check if existing static trait property is a ref before …
Browse files Browse the repository at this point in the history
…comparing
  • Loading branch information
pmmaga authored and nikic committed Dec 16, 2017
1 parent a20c9bd commit 83964e0
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 4 deletions.
25 changes: 25 additions & 0 deletions Zend/tests/traits/bug75607.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--TEST--
Bug #75607 (Comparision of initial static properties failing)
--FILE--
<?php

trait T1
{
public static $prop1 = 1;
}

class Base
{
public static $prop1 = 1;
}

class Child extends base
{
use T1;
}

echo "DONE";

?>
--EXPECT--
DONE
36 changes: 36 additions & 0 deletions Zend/tests/traits/bug75607a.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
--TEST--
Bug #75607 (Comparision of initial static properties failing)
--FILE--
<?php

trait T1
{
public static $prop1 = 1;
}

trait T2
{
public static $prop1 = 1;
}

class Base
{
use T1;
}

class Child extends base
{

}

class Grand extends Child
{
use T2;
}

$c = new Grand();
var_dump($c::$prop1);

?>
--EXPECT--
int(1)
12 changes: 8 additions & 4 deletions Zend/zend_inheritance.c
Original file line number Diff line number Diff line change
Expand Up @@ -1568,13 +1568,17 @@ static void zend_do_traits_property_binding(zend_class_entry *ce) /* {{{ */
if ((coliding_prop->flags & (ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC))
== (flags & (ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC))) {
/* flags are identical, now the value needs to be checked */
zval *op1, *op2;
if (flags & ZEND_ACC_STATIC) {
not_compatible = fast_is_not_identical_function(&ce->default_static_members_table[coliding_prop->offset],
&ce->traits[i]->default_static_members_table[property_info->offset]);
op1 = &ce->default_static_members_table[coliding_prop->offset];
op2 = &ce->traits[i]->default_static_members_table[property_info->offset];
ZVAL_DEREF(op1);
ZVAL_DEREF(op2);
} else {
not_compatible = fast_is_not_identical_function(&ce->default_properties_table[OBJ_PROP_TO_NUM(coliding_prop->offset)],
&ce->traits[i]->default_properties_table[OBJ_PROP_TO_NUM(property_info->offset)]);
op1 = &ce->default_properties_table[OBJ_PROP_TO_NUM(coliding_prop->offset)];
op2 = &ce->traits[i]->default_properties_table[OBJ_PROP_TO_NUM(property_info->offset)];
}
not_compatible = fast_is_not_identical_function(op1, op2);
} else {
/* the flags are not identical, thus, we assume properties are not compatible */
not_compatible = 1;
Expand Down

0 comments on commit 83964e0

Please sign in to comment.