diff --git a/language/oop5/visibility.xml b/language/oop5/visibility.xml index 8c9840595c..456b5627ee 100644 --- a/language/oop5/visibility.xml +++ b/language/oop5/visibility.xml @@ -3,7 +3,7 @@ Visibility - The visibility of a property or method can be defined by prefixing + The visibility of a property, a method or (as of PHP 7.1.0) a constant can be defined by prefixing the declaration with the keywords public, protected or private. Class members declared public can be @@ -189,6 +189,72 @@ $myFoo->test(); // Bar::testPrivate + + Constant Visibility + + As of PHP 7.1.0, class constants may be defined as public, private, or + protected. Constants declared without any explicit visibility + keyword are defined as public. + + + + Constant Declaration as of PHP 7.1.0 + +foo(); // Public, Protected and Private work + + +/** + * Define MyClass2 + */ +class MyClass2 extends MyClass +{ + // This is public + function foo2() + { + echo self::MY_PUBLIC; + echo self::MY_PROTECTED; + echo self::MY_PRIVATE; // Fatal Error + } +} + +$myclass2 = new MyClass2; +echo MyClass2::MY_PUBLIC; // Works +$myclass2->foo2(); // Public and Protected work, not Private +?> +]]> + + + + + Visibility from other objects