3v4l.org

run code in 300+ PHP versions simultaneously
<?php class X { } class XFactory { private $className = 'X'; private function getClassName() { return $this->className; } public function create() { return array( 'member without parens' => new $this->className, 'member with parens' => new $this->className(), // 'method without parens' => new $this->getClassName, # Does not work at all 'method with parens' => new $this->getClassName(), 'method with double parens' => new ($this->getClassName())(), 'method with encapsed parens' => new ($this->getClassName())(), ); } } $factory = new XFactory(); var_dump($factory->create());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ErFI9
function name:  (null)
number of ops:  9
compiled vars:  !0 = $factory
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   NEW                                              $1      'XFactory'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   30     3        INIT_FCALL                                               'var_dump'
          4        INIT_METHOD_CALL                                         !0, 'create'
          5        DO_FCALL                                      0  $4      
          6        SEND_VAR                                                 $4
          7        DO_ICALL                                                 
          8      > RETURN                                                   1

Class X: [no user functions]
Class XFactory:
Function getclassname:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ErFI9
function name:  getClassName
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   FETCH_OBJ_R                                      ~0      'className'
          1      > RETURN                                                   ~0
   14     2*     > RETURN                                                   null

End of function getclassname

Function create:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ErFI9
function name:  create
number of ops:  29
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   FETCH_OBJ_R                                      ~0      'className'
          1        FETCH_CLASS                                   0  $1      ~0
          2        NEW                                              $2      $1
          3        DO_FCALL                                      0          
          4        INIT_ARRAY                                       ~4      $2, 'member+without+parens'
   20     5        FETCH_OBJ_R                                      ~5      'className'
          6        FETCH_CLASS                                   0  $6      ~5
          7        NEW                                              $7      $6
          8        DO_FCALL                                      0          
          9        ADD_ARRAY_ELEMENT                                ~4      $7, 'member+with+parens'
   22    10        FETCH_OBJ_R                                      ~9      'getClassName'
         11        FETCH_CLASS                                   0  $10     ~9
         12        NEW                                              $11     $10
         13        DO_FCALL                                      0          
         14        ADD_ARRAY_ELEMENT                                ~4      $11, 'method+with+parens'
   23    15        INIT_METHOD_CALL                                         'getClassName'
         16        DO_FCALL                                      0  $13     
         17        FETCH_CLASS                                   0  $14     $13
         18        NEW                                              $15     $14
         19        DO_FCALL                                      0          
         20        ADD_ARRAY_ELEMENT                                ~4      $15, 'method+with+double+parens'
   24    21        INIT_METHOD_CALL                                         'getClassName'
         22        DO_FCALL                                      0  $17     
         23        FETCH_CLASS                                   0  $18     $17
         24        NEW                                              $19     $18
         25        DO_FCALL                                      0          
         26        ADD_ARRAY_ELEMENT                                ~4      $19, 'method+with+encapsed+parens'
         27      > RETURN                                                   ~4
   26    28*     > RETURN                                                   null

End of function create

End of class XFactory.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.84 ms | 1400 KiB | 15 Q