3v4l.org

run code in 500+ PHP versions simultaneously
<?php // cet exemple est issue de la documentation https://www.php.net/manual/fr/language.oop5.variance.php declare(strict_types=1); class Food {} // la classe AnimalFood hérite de Food class AnimalFood extends Food {} abstract class Animal { protected string $name; public function __construct(string $name) { $this->name = $name; } // Initialement un animal mange de la nouriture animale. public function eat(AnimalFood $food) { echo $this->name . " eats " . get_class($food); } } class Dog extends Animal { // Puisque la nouriture animale est avant tout de la nouriture, alors il est possible d'élargir le choix // en précisant juste nouriture. C'est toujours valide :) Le chien ne s'en plaindra pas. // Par contre un poisson... ne mangera probablement pas une côte de boeuf... // Il faut pouvoir conserver le comportement original, et garantir la nouriture appropriée. // Ceci s'appelle la contravariance. public function eat(Food $food) { echo $this->name . " eats " . get_class($food); } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Hc1tm
function name:  (null)
number of ops:  1
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   38     0  E > > RETURN                                                       1

Class Food: [no user functions]
Class AnimalFood: [no user functions]
Class Animal:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Hc1tm
function name:  __construct
number of ops:  4
compiled vars:  !0 = $name
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   16     0  E >   RECV                                                 !0      
   18     1        ASSIGN_OBJ                                                   'name'
          2        OP_DATA                                                      !0
   19     3      > RETURN                                                       null

End of function __construct

Function eat:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Hc1tm
function name:  eat
number of ops:  7
compiled vars:  !0 = $food
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   22     0  E >   RECV                                                 !0      
   24     1        FETCH_OBJ_R                                          ~1      'name'
          2        CONCAT                                               ~2      ~1, '+eats+'
          3        GET_CLASS                                            ~3      !0
          4        CONCAT                                               ~4      ~2, ~3
          5        ECHO                                                         ~4
   25     6      > RETURN                                                       null

End of function eat

End of class Animal.

Class Dog:
Function eat:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Hc1tm
function name:  eat
number of ops:  7
compiled vars:  !0 = $food
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   35     0  E >   RECV                                                 !0      
   36     1        FETCH_OBJ_R                                          ~1      'name'
          2        CONCAT                                               ~2      ~1, '+eats+'
          3        GET_CLASS                                            ~3      !0
          4        CONCAT                                               ~4      ~2, ~3
          5        ECHO                                                         ~4
   37     6      > RETURN                                                       null

End of function eat

Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Hc1tm
function name:  __construct
number of ops:  4
compiled vars:  !0 = $name
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   16     0  E >   RECV                                                 !0      
   18     1        ASSIGN_OBJ                                                   'name'
          2        OP_DATA                                                      !0
   19     3      > RETURN                                                       null

End of function __construct

End of class Dog.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
160.33 ms | 1994 KiB | 13 Q