Bug #75449 [Com]: Ignored return type for abstract methods, defined in traits
| From: | saintatgod at gmail dot com | Date: | Tue, 31 Oct 2017 02:12:57 +0000 |
| Subject: | Bug #75449 [Com]: Ignored return type for abstract methods, defined in traits | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-212383@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75449&edit=1
ID: 75449
Comment by: saintatgod at gmail dot com
Reported by: alex dot rill at yandex dot ru
Summary: Ignored return type for abstract methods, defined in
traits
Status: Open
Type: Bug
Package: Class/Object related
Operating System: Windows
PHP Version: 7.1.11
Block user comment: N
Private report: N
New Comment:
<?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();
Previous Comments:
------------------------------------------------------------------------
[2017-10-31 01:43:27] saintatgod at gmail dot com
where is Class D ?
------------------------------------------------------------------------
[2017-10-28 06:25:31] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75449&edit=1