mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Tests show updating consts must happen once at runtime (revert optimization).
Add tests for static properties.
This commit is contained in:
parent
4e7a782f3a
commit
95649ab260
5 changed files with 92 additions and 2 deletions
|
@ -700,6 +700,7 @@ ZEND_API int _object_and_properties_init(zval *arg, zend_class_entry *class_type
|
|||
|
||||
if (!class_type->constants_updated) {
|
||||
zend_hash_apply_with_argument(&class_type->default_properties, (apply_func_arg_t) zval_update_constant, (void *) 1 TSRMLS_CC);
|
||||
zend_hash_apply_with_argument(class_type->static_members, (apply_func_arg_t) zval_update_constant, (void *) 1 TSRMLS_CC);
|
||||
class_type->constants_updated = 1;
|
||||
}
|
||||
|
||||
|
@ -1683,8 +1684,6 @@ ZEND_API int zend_declare_property(zend_class_entry *ce, char *name, int name_le
|
|||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
zval_update_constant(&property, (void *) 1 TSRMLS_CC);
|
||||
}
|
||||
switch (access_type & ZEND_ACC_PPP_MASK) {
|
||||
case ZEND_ACC_PRIVATE: {
|
||||
|
|
|
@ -722,6 +722,7 @@ static void zend_fetch_var_address(zend_op *opline, temp_variable *Ts, int type
|
|||
FREE_OP(Ts, &opline->op1, free_op1);
|
||||
break;
|
||||
case ZEND_FETCH_STATIC:
|
||||
zval_update_constant(retval, (void*) 1 TSRMLS_CC);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -736,6 +736,7 @@ zval **zend_std_get_static_property(zend_class_entry *ce, char *property_name, i
|
|||
}
|
||||
}
|
||||
|
||||
zval_update_constant(retval, (void *) 1 TSRMLS_CC);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
|
62
ext/reflection/tests/static_properties_002.phpt
Executable file
62
ext/reflection/tests/static_properties_002.phpt
Executable file
|
@ -0,0 +1,62 @@
|
|||
--TEST--
|
||||
ZE2 Inheriting static properties
|
||||
--SKIPIF--
|
||||
<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
class base {
|
||||
static protected $prop = 2;
|
||||
|
||||
static function show() {
|
||||
echo __METHOD__ . '(' . self::$prop . ")\n";
|
||||
}
|
||||
|
||||
static function inc() {
|
||||
base::$prop++;
|
||||
echo __METHOD__ . "()\n";
|
||||
}
|
||||
}
|
||||
|
||||
class derived extends base {
|
||||
static public $prop;
|
||||
|
||||
static function show() {
|
||||
echo __METHOD__ . '(' . self::$prop . ")\n";
|
||||
}
|
||||
|
||||
static function inc() {
|
||||
derived::$prop++;
|
||||
echo __METHOD__ . "()\n";
|
||||
}
|
||||
}
|
||||
|
||||
base::show();
|
||||
derived::show();
|
||||
|
||||
base::inc();
|
||||
|
||||
base::show();
|
||||
derived::show();
|
||||
|
||||
derived::inc();
|
||||
|
||||
base::show();
|
||||
derived::show();
|
||||
|
||||
$r = new reflection_class('derived');
|
||||
echo 'Number of properties: '. count($r->getStaticProperties()) . "\n";
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
base::show(2)
|
||||
derived::show(2)
|
||||
base::inc()
|
||||
base::show(3)
|
||||
derived::show(3)
|
||||
derived::inc()
|
||||
base::show(4)
|
||||
derived::show(4)
|
||||
Number of properties: 1
|
||||
Done
|
27
tests/classes/static_properties_001.phpt
Executable file
27
tests/classes/static_properties_001.phpt
Executable file
|
@ -0,0 +1,27 @@
|
|||
--TEST--
|
||||
ZE2 Initializing static properties to arrays
|
||||
--SKIPIF--
|
||||
<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
class test {
|
||||
static public $ar = array();
|
||||
}
|
||||
|
||||
var_dump(test::$ar);
|
||||
|
||||
test::$ar[] = 1;
|
||||
|
||||
var_dump(test::$ar);
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
array(0) {
|
||||
}
|
||||
array(1) {
|
||||
[0]=>
|
||||
int(1)
|
||||
}
|
||||
Done
|
Loading…
Add table
Add a link
Reference in a new issue