Doc #81038 [NEW]: the variance and traits

From: Date: Thu, 13 May 2021 12:55:25 +0000
Subject: Doc #81038 [NEW]: the variance and traits
Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-18761@lists.php.net to get a copy of this message
From:             sh-ya at ya dot ru
Operating system: 
PHP version:      7.4.19
Package:          Documentation problem
Bug Type:         Documentation Problem
Bug description:the variance and traits

Description:
------------
using the variance requires pre-definition of classes that use traits

Test script:
---------------
interface Animal {
	public function eat(AnimalFood $food);
}

class Dog implements Animal {
	public function eat(Food $food) {}
}

trait SomeTrait {
	public $b = true;
}

class Food {
	use SomeTrait;
	public $i = 0;
}

class AnimalFood extends Food {}


var_dump(new AnimalFood);


Expected result:
----------------
object(AnimalFood)#1 (2) {
  ["i"]=>
  int(0)
  ["b"]=>
  bool(true)
}

Actual result:
--------------
Fatal error: Could not check compatibility between Dog::eat(Food $food)
and Animal::eat(AnimalFood $food), because class AnimalFood is not
available in ...

-- 
Edit bug report at https://bugs.php.net/bug.php?id=81038&edit=1
-- 
Fix committed:                    https://bugs.php.net/fix.php?id=81038&r=fixed
Fixed in release:                 https://bugs.php.net/fix.php?id=81038&r=alreadyfixed
Need backtrace:                   https://bugs.php.net/fix.php?id=81038&r=needtrace
Need Reproduce Script:            https://bugs.php.net/fix.php?id=81038&r=needscript
Try newer version:                https://bugs.php.net/fix.php?id=81038&r=oldversion
Not developer issue:              https://bugs.php.net/fix.php?id=81038&r=support
Expected behavior:                https://bugs.php.net/fix.php?id=81038&r=notwrong
Not enough info:                  https://bugs.php.net/fix.php?id=81038&r=notenoughinfo
Submitted twice:                  https://bugs.php.net/fix.php?id=81038&r=submittedtwice
register_globals:                 https://bugs.php.net/fix.php?id=81038&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=81038&r=phptooold
Daylight Savings:                 https://bugs.php.net/fix.php?id=81038&r=dst
IIS Stability:                    https://bugs.php.net/fix.php?id=81038&r=isapi
Install GNU Sed:                  https://bugs.php.net/fix.php?id=81038&r=gnused
Floating point limitations:       https://bugs.php.net/fix.php?id=81038&r=float
No Zend Extensions:               https://bugs.php.net/fix.php?id=81038&r=nozend
MySQL Configuration Error:        https://bugs.php.net/fix.php?id=81038&r=mysqlcfg


Thread (9 messages)

« previous php.doc.bugs (#18761) next »