|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2017-10-28 06:25 UTC] alex dot rill at yandex dot ru
Description: ------------ Dont speak english. All in example code. --- From manual page: http://www.php.net/language.oop5.traits --- Test script: --------------- <?php trait T { abstract static function values(): array; } class B { use T; static function values() { return 'Worked!'; // string, not array } } echo B::values(); // print: Worked! abstract class B { use T; } class C extends B { static function values() { return 'Don\'t worked'; } } echo C::values(); // Fatal Error: Class D contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (C::values) ?> Online example: http://sandbox.onlinephpfunctions.com/code/7b26e7237abcf97d15aac6a0868c084241bf8d0c PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Dec 08 07:00:01 2025 UTC |
<?php trait T { abstract static function values(): array; } //class B { // use T; // static function values() { // return 'Worked!'; // string, not array // } //} //echo B::valuesi(); // print: Worked! abstract class B { use T; self::values(); // if inheritance trait, must implement abstract function in trait } class C extends B { static function values() { return 'Don\'t worked'; } } echo C::values();