Skip to content

Implement typed properties #3734

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 56 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
46fbe12
Implement typed properties
nikic Jan 7, 2019
973f8c5
Remove redundant trailing newlines from tests
nikic Jan 7, 2019
784aebe
Coding style tweaks
nikic Jan 7, 2019
ac6b431
Add test for typed properties on internal class
nikic Jan 7, 2019
d95f131
Code cleanup
nikic Jan 7, 2019
0395fe5
Avoid direct uses of zend_try_assign API
nikic Jan 7, 2019
37b3de6
Remove alloc_polymorphic_cache_slots API
nikic Jan 7, 2019
5e009e7
Rename get_mangled_property_name to get_unmangled_property_name
nikic Jan 7, 2019
9e82c5a
Cleanup code and add more trait + self tests
nikic Jan 7, 2019
be0cfbb
Restore exception
nikic Jan 8, 2019
9c55d73
Remove requirement that reference sources must have resolved types
nikic Jan 8, 2019
23bb53f
Tweak assign_to_variable
nikic Jan 8, 2019
b4f5e11
Remove dubious expectations
nikic Jan 8, 2019
f1d9f22
Move error generation into verify_property_type
nikic Jan 8, 2019
117d1da
Code cleanup
nikic Jan 8, 2019
3923574
Check for incdec overflow if no refs are involved
nikic Jan 8, 2019
be63cc1
Prefer showing a property type error over a reference error
nikic Jan 8, 2019
1282365
Extract error code into cold function
nikic Jan 8, 2019
ee84e01
Code cleanup
nikic Jan 8, 2019
bc27695
Fix handling of null vs undef in auto-vivification
nikic Jan 8, 2019
ba09a1d
Fix hardcoded paths in tests
nikic Jan 9, 2019
4e34d90
Cleanup
nikic Jan 9, 2019
dcefc11
More changes to initialization handling
nikic Jan 9, 2019
6cc4f84
Inherit the HAS_TYPE_HINTS flag
nikic Jan 9, 2019
3ae6f61
Set HAS_TYPE_HINTS for static props as well
nikic Jan 9, 2019
e9ee417
Reuse object flag code for static props
nikic Jan 9, 2019
07b95d5
Move TODO comment
nikic Jan 9, 2019
c6bd1d9
In debug mode, we want to make sure that refs do have type sources
nikic Jan 9, 2019
f103983
Compile by-ref foreach with the by_ref flag
nikic Jan 9, 2019
9fdb55d
Fix handling of private properties in foreach
nikic Jan 9, 2019
0245c68
Exit early for strict_types in verify_type_assignable_zval
nikic Jan 9, 2019
9f2734a
Code cleanup
nikic Jan 9, 2019
a427595
Remove dependence on zend_resolve_property_type
nikic Jan 9, 2019
1327829
Fix ref assignable with strict types
nikic Jan 9, 2019
22dfc44
Only use information from visible properties in opcache
nikic Jan 9, 2019
90cfd7a
Make sure fetch_property_type_info is only used with valid offset
nikic Jan 9, 2019
dcc8ea8
write_property value may not be REF
nikic Jan 9, 2019
cfd76b0
Use faster API too look up property info in object handlers
nikic Jan 10, 2019
efbcbd6
Fix dumping of private uninitialized props
nikic Jan 10, 2019
bb3e82b
Move everything over to the slot API
nikic Jan 10, 2019
1005f92
Use slot API during cloning
nikic Jan 10, 2019
88d966b
Remove bogus DEREF
nikic Jan 10, 2019
8b1a6a3
Remove unnecessary SEPARATE
nikic Jan 10, 2019
d1ac734
Prefer checking type prior to modification
nikic Jan 10, 2019
dc68354
Fix ref post incdec without type sources
nikic Jan 10, 2019
d7dbf11
Remove manual ref sources initialization
nikic Jan 10, 2019
223cd77
Property dump DIM_WRITE/OBJ_WRITE flags
nikic Jan 10, 2019
5b7a5b0
Remove bogus PARAM_ZVAL_DEREF
nikic Jan 10, 2019
df34631
Convert checks to assertions
nikic Jan 10, 2019
fa59a56
Use slot API in unserialization
nikic Jan 10, 2019
26139a4
Fetch class types in property hints in opcache
nikic Jan 10, 2019
4eec659
Move ASSIGN_OBJ_REF to the right place
nikic Jan 10, 2019
e6510a5
Support typed properties in opcache file cache
nikic Jan 10, 2019
8264d27
Also handle CE types in persistence
nikic Jan 10, 2019
6150ddd
Add UPGRADING entry
nikic Jan 10, 2019
7e7b446
Add UPGRADING.INTERNALS notes
nikic Jan 10, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test for typed properties on internal class
  • Loading branch information
nikic committed Jan 10, 2019
commit ac6b4310978cae399a5d4246edab9fb6001e1389
84 changes: 84 additions & 0 deletions Zend/tests/type_declarations/typed_properties_095.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
--TEST--
Typed properties in internal classes
--SKIPIF--
<?php if (!extension_loaded('zend-test')) die('skip requires zend-test'); ?>
--FILE--
<?php

// Internal typed properties

$obj = new _ZendTestClass;
var_dump($obj->intProp);
try {
$obj->intProp = "foobar";
} catch (TypeError $e) {
echo $e->getMessage(), "\n";
}
$obj->intProp = 456;

try {
$obj->classProp = $obj;
} catch (TypeError $e) {
echo $e->getMessage(), "\n";
}
$obj->classProp = new stdClass;
var_dump($obj);

// Inherit from internal class

class Test extends _ZendTestClass {
}

$obj = new Test;
var_dump($obj->intProp);
try {
$obj->intProp = "foobar";
} catch (TypeError $e) {
echo $e->getMessage(), "\n";
}
$obj->intProp = 456;

try {
$obj->classProp = $obj;
} catch (TypeError $e) {
echo $e->getMessage(), "\n";
}
$obj->classProp = new stdClass;
var_dump($obj);

// Static internal typed properties

var_dump(_ZendTestClass::$staticIntProp);
try {
_ZendTestClass::$staticIntProp = "foobar";
} catch (TypeError $e) {
echo $e->getMessage(), "\n";
}
_ZendTestClass::$staticIntProp = 456;
var_dump(_ZendTestClass::$staticIntProp);

?>
--EXPECT--
int(123)
Typed property _ZendTestClass::$intProp must be int, string used
Typed property _ZendTestClass::$classProp must be an instance of stdClass or null, _ZendTestClass used
object(_ZendTestClass)#1 (2) {
["intProp"]=>
int(456)
["classProp"]=>
object(stdClass)#2 (0) {
}
}
int(123)
Typed property _ZendTestClass::$intProp must be int, string used
Typed property _ZendTestClass::$classProp must be an instance of stdClass or null, Test used
object(Test)#4 (2) {
["intProp"]=>
int(456)
["classProp"]=>
object(stdClass)#1 (0) {
}
}
int(123)
Typed property _ZendTestClass::$staticIntProp must be int, string used
int(456)
1 change: 0 additions & 1 deletion Zend/zend.c
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,6 @@ int zend_post_startup(void) /* {{{ */
global_persistent_list = &EG(persistent_list);
zend_copy_ini_directives();
#else
zend_resolve_property_types();
global_map_ptr_last = CG(map_ptr_last);
#endif

Expand Down
31 changes: 31 additions & 0 deletions ext/zend_test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ ZEND_FUNCTION(zend_leak_variable)

static zend_object *zend_test_class_new(zend_class_entry *class_type) /* {{{ */ {
zend_object *obj = zend_objects_new(class_type);
object_properties_init(obj, class_type);
obj->handlers = &zend_test_class_handlers;
return obj;
}
Expand Down Expand Up @@ -203,6 +204,36 @@ PHP_MINIT_FUNCTION(zend_test)

zend_declare_property_null(zend_test_class, "_StaticProp", sizeof("_StaticProp") - 1, ZEND_ACC_STATIC);

{
zend_string *name = zend_string_init("intProp", sizeof("intProp") - 1, 1);
zval val;
ZVAL_LONG(&val, 123);
zend_declare_typed_property(
zend_test_class, name, &val, ZEND_ACC_PUBLIC, NULL, ZEND_TYPE_ENCODE(IS_LONG, 0));
zend_string_release(name);
}

{
zend_string *name = zend_string_init("classProp", sizeof("classProp") - 1, 1);
zend_string *class_name = zend_string_init("stdClass", sizeof("stdClass") - 1, 1);
zval val;
ZVAL_NULL(&val);
zend_declare_typed_property(
zend_test_class, name, &val, ZEND_ACC_PUBLIC, NULL,
ZEND_TYPE_ENCODE_CLASS(class_name, 1));
zend_string_release(name);
}

{
zend_string *name = zend_string_init("staticIntProp", sizeof("staticIntProp") - 1, 1);
zval val;
ZVAL_LONG(&val, 123);
zend_declare_typed_property(
zend_test_class, name, &val, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC, NULL,
ZEND_TYPE_ENCODE(IS_LONG, 0));
zend_string_release(name);
}

INIT_CLASS_ENTRY(class_entry, "_ZendTestChildClass", NULL);
zend_test_child_class = zend_register_internal_class_ex(&class_entry, zend_test_class);

Expand Down