diff --git a/language/oop5/properties.xml b/language/oop5/properties.xml index 9fc60965ea20..3ccb9b26c1a3 100644 --- a/language/oop5/properties.xml +++ b/language/oop5/properties.xml @@ -257,6 +257,35 @@ $test1->prop = "foobar"; + + + Readonly properties can only be initialized by a direct assignment. + An uninitialized readonly property cannot be initialized by reference, not even + from the scope where it has been declared: passing it to a function parameter that + expects to be passed by reference, or assigning it by reference, results in an + Error exception. + + +matches); + // Error: Cannot indirectly modify readonly property Test::$matches + } +} + +new Test('abc 42'); +?> +]]> + + + + Specifying an explicit default value on readonly properties is not allowed, because a readonly property with a default value is essentially the same as a constant, and thus not particularly useful.