3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Ancestor { public $publicVar = "ancestor's public var\n"; static $staticVar = "ancestor's static var\n"; function publicMethod(){ echo "ancestor's publicMethod "; // is $this is set up if(isset($this)){ echo 'is in object context. get_class($this):'.get_class($this).". get_class():".get_class().". __CLASS__:".__CLASS__.".\n"; }else{ echo "is in static context. get_class():".get_class().". __CLASS__:".__CLASS__.".\n"; } } static function staticMethod(){ echo "ancestor's staticMethod "; // is $this is set up if(isset($this)){ echo 'in object context. get_class($this):'.get_class($this).". get_class():".get_class().". __CLASS__:".__CLASS__.".\n"; }else{ echo "in static context. get_class():".get_class().". __CLASS__:".__CLASS__.".\n"; } } function publicMethodDeclaredInAncestor(){ echo "publicMethodDeclaredInAncestor "; // is $this is set up if(isset($this)){ echo 'is in object context. get_class($this):'.get_class($this).". get_class():".get_class().". __CLASS__:".__CLASS__.".\n"; }else{ echo "is in static context. get_class():".get_class().". __CLASS__:".__CLASS__.".\n"; } } static function staticMethodDeclaredInAncestor(){ echo "staticMethodDeclaredInAncestor "; // is $this is set up if(isset($this)){ echo 'in object context. get_class($this):'.get_class($this).". get_class():".get_class().". __CLASS__:".__CLASS__.".\n"; }else{ echo "in static context. get_class():".get_class().". __CLASS__:".__CLASS__.".\n"; } } } class Descendant extends Ancestor { public $publicVar = "descendant's public var\n"; static $staticVar = "descendant's static var\n"; function publicMethod(){ echo "descendant's publicMethod "; // is $this is set up if(isset($this)){ echo 'in object context. get_class($this):'.get_class($this).". get_class():".get_class().". __CLASS__:".__CLASS__.".\n"; }else{ echo "in static context. get_class():".get_class().". __CLASS__:".__CLASS__.".\n"; } } static function staticMethod(){ echo "descendant's staticMethod "; // is $this is set up if(isset($this)){ echo 'in object context. get_class($this):'.get_class($this).". get_class():".get_class().". __CLASS__:".__CLASS__.". \n"; }else{ echo "in static context. get_class(self):".get_class(self).". __CLASS__:".__CLASS__.".\n"; } } function publicMethodDeclaredInDescendant(){ echo "publicMethodDeclaredInDescendant "; // is $this is set up if(isset($this)){ echo 'in object context. get_class($this):'.get_class($this).". get_class():".get_class().". __CLASS__:".__CLASS__.".\n"; }else{ echo "in static context. get_class():".get_class().". __CLASS__:".__CLASS__.".\n"; } } static function staticMethodDeclaredInDescendant(){ echo "staticMethodDeclaredInDescendant "; // is $this is set up if(isset($this)){ echo 'in object context. get_class($this):'.get_class($this).". get_class():".get_class().". __CLASS__:".__CLASS__.".\n"; }else{ echo "in static context. get_class():".get_class().". __CLASS__:".__CLASS__.".\n"; } } function callToPropertiesFromPublicContext(){ echo $this->publicVar; // descendant's public var //echo $this->staticVar; // "" + notice: Undefined property: Descendant::$staticVar //echo $this::$publicVar; // fatal error: Access to undeclared static property: Descendant::$publicVar echo $this::$staticVar; // descendant's static var //echo Descendant::$publicVar; // fatal error: Access to undeclared static property: Descendant::$publicVar echo Descendant::$staticVar; // descendant's static var } static function callToPropertiesFromStaticContext(){ //echo Descendant::$publicVar; // fatal error: Access to undeclared static property: Descendant::$publicVar echo Descendant::$staticVar; // descendant's static var } function callMethodsFromPublicContext() { $this->publicMethod(); // descendant's publicMethod in object context $this->staticMethod(); // descendant's staticMethod in static context $this::publicMethod(); // descendant's publicMethod in object context $this::staticMethod(); // descendant's staticMethod in static context Descendant::publicMethod(); // descendant's publicMethod in object context Descendant::staticMethod(); // descendant's staticMethod in static context } static function callMethodsFromStaticContext() { Descendant::publicMethod(); // descendant's publicMethod in static context (deprecated) Descendant::staticMethod(); // descendant's staticMethod in static context } function callWithSelfFromPublicContext() { self::publicMethod(); self::publicMethodDeclaredInAncestor(); self::publicMethodDeclaredInDescendant(); self::staticMethod(); self::staticMethodDeclaredInAncestor(); self::staticMethodDeclaredInDescendant(); } static function callWithSelfFromStaticContext() { self::publicMethod(); self::publicMethodDeclaredInAncestor(); self::publicMethodDeclaredInDescendant(); self::staticMethod(); self::staticMethodDeclaredInAncestor(); self::staticMethodDeclaredInDescendant(); } } $ancestor = new Ancestor(); $descendant = new Descendant(); echo "\n1. From Outside Of An Instance/Class:\n"; echo "\n----- 1.1 access to properties -----\n"; echo $descendant->publicVar; // descendant's public var //echo $descendant->staticVar; // "" + notice: Undefined property: Descendant::$staticVar //echo $descendant::$publicVar; // fatal error: Access to undeclared static property: Descendant::$publicVar echo $descendant::$staticVar; // descendant's static var //echo Descendant::$publicVar; // fatal error: Access to undeclared static property echo Descendant::$staticVar; // descendant's static var echo "\n----- 1.2 access to methods -----\n"; $descendant->publicMethod(); // descendant's publicMethod in object context $descendant->staticMethod(); // descendant's staticMethod in static context $descendant::publicMethod(); // descendant's publicMethod in static context (deprecated) $descendant::staticMethod(); // descendant's staticMethod in static context Descendant::publicMethod(); // descendant's publicMethod in static context (deprecated) Descendant::staticMethod(); // descendant's staticMethod in static context echo "\n2. From Inside Of An Instance/Class:\n"; echo "\n----- 2.1 access to properties from public context -----\n"; $descendant->callToPropertiesFromPublicContext(); //echo $this->publicVar; // descendant's public var //echo $this->staticVar; // "" + notice: Undefined property: Descendant::$staticVar //echo $this::$publicVar; // fatal error: Access to undeclared static property: Descendant::$publicVar //echo $this::$staticVar; // descendant's static var // //echo Descendant::$publicVar; // fatal error: Access to undeclared static property: Descendant::$publicVar //echo Descendant::$staticVar; // descendant's static var echo "\n----- 2.2 access to properties from static context -----\n"; $descendant->callToPropertiesFromStaticContext(); //echo Descendant::$publicVar; // fatal error: Access to undeclared static property: Descendant::$publicVar //echo Descendant::$staticVar; // descendant's static var echo "\n----- 2.3 access to methods from public context -----\n"; $descendant->callMethodsFromPublicContext(); //$this->publicMethod(); // descendant's publicMethod in object context //$this->staticMethod(); // descendant's staticMethod in static context //$this::publicMethod(); // descendant's publicMethod in object context //$this::staticMethod(); // descendant's staticMethod in static context // //Descendant::publicMethod(); // descendant's publicMethod in object context //Descendant::staticMethod(); // descendant's staticMethod in static context echo "\n----- 2.4 access to methods from static context -----\n"; $descendant->callMethodsFromStaticContext(); //Descendant::publicMethod(); // descendant's publicMethod in static context (deprecated) //Descendant::staticMethod(); // descendant's staticMethod in static context echo "\n3. From Inside with 'forwarding calls' :\n"; echo "\n----- 3.1 self from public context -----\n"; $descendant->callWithSelfFromPublicContext(); // self::publicMethod(); // // self::publicMethodDeclaredInAncestor(); // self::publicMethodDeclaredInDescendant(); // self::staticMethod(); // self::staticMethodDeclaredInAncestor(); // self::staticMethodDeclaredInDescendant(); // descendant's publicMethod in object context. get_class($this):Descendant. get_class():Descendant. __CLASS__:Descendant. // publicMethodDeclaredInAncestor is in object context. get_class($this):Descendant. get_class():Ancestor. __CLASS__:Ancestor. // publicMethodDeclaredInDescendant in object context. get_class($this):Descendant. get_class():Descendant. __CLASS__:Descendant. // descendant's staticMethod in static context. get_class():Descendant. __CLASS__:Descendant. // staticMethodDeclaredInAncestor in static context. get_class():Ancestor. __CLASS__:Ancestor. // staticMethodDeclaredInDescendant in static context. get_class():Descendant. __CLASS__:Descendant. echo "\n----- 3.2 self from static context -----\n"; Descendant::callWithSelfFromStaticContext(); // self::publicMethod(); // self::publicMethodDeclaredInAncestor(); // self::publicMethodDeclaredInDescendant(); // self::staticMethod(); // self::staticMethodDeclaredInAncestor(); // self::staticMethodDeclaredInDescendant(); // descendant's publicMethod in static context. get_class():Descendant. __CLASS__:Descendant. // publicMethodDeclaredInAncestor is in static context. get_class():Ancestor. __CLASS__:Ancestor. // publicMethodDeclaredInDescendant in static context. get_class():Descendant. __CLASS__:Descendant. // descendant's staticMethod in static context. get_class():Descendant. __CLASS__:Descendant. // staticMethodDeclaredInAncestor in static context. get_class():Ancestor. __CLASS__:Ancestor. // staticMethodDeclaredInDescendant in static context. get_class():Descendant. __CLASS__:Descendant. // parent // static

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.3.60.0100.01316.75
8.3.50.0110.00716.26
8.3.40.0040.01118.69
8.3.30.0090.00618.71
8.3.20.0040.00420.29
8.3.10.0070.01023.59
8.3.00.0060.00317.93
8.2.180.0110.01116.88
8.2.170.0130.00922.96
8.2.160.0070.00720.39
8.2.150.0000.00824.18
8.2.140.0080.00024.66
8.2.130.0040.00426.16
8.2.120.0030.00617.75
8.2.110.0030.00620.95
8.2.100.0090.00318.03
8.2.90.0050.00317.97
8.2.80.0110.00018.01
8.2.70.0030.00617.50
8.2.60.0060.00317.93
8.2.50.0060.00318.07
8.2.40.0000.00719.45
8.2.30.0080.00018.03
8.2.20.0000.00817.69
8.2.10.0050.00318.04
8.2.00.0040.00418.18
8.1.280.0070.00725.92
8.1.270.0110.00721.98
8.1.260.0080.00026.35
8.1.250.0120.00828.09
8.1.240.0100.01022.54
8.1.230.0040.00820.93
8.1.220.0060.00317.74
8.1.210.0000.00918.86
8.1.200.0060.00317.22
8.1.190.0060.00317.38
8.1.180.0040.00418.10
8.1.170.0040.00418.56
8.1.160.0040.00422.09
8.1.150.0060.00318.93
8.1.140.0030.00617.53
8.1.130.0040.00417.73
8.1.120.0040.00417.48
8.1.110.0000.00717.56
8.1.100.0040.00417.55
8.1.90.0040.00417.48
8.1.80.0040.00417.40
8.1.70.0030.00617.41
8.1.60.0090.00017.65
8.1.50.0060.00317.61
8.1.40.0050.00517.57
8.1.30.0030.00517.66
8.1.20.0060.00317.66
8.1.10.0040.00417.55
8.1.00.0000.00717.58
8.0.300.0040.00420.02
8.0.290.0040.00417.00
8.0.280.0070.00018.56
8.0.270.0000.00817.37
8.0.260.0030.00317.32
8.0.250.0080.00017.01
8.0.240.0040.00417.14
8.0.230.0030.00316.96
8.0.220.0030.00317.04
8.0.210.0030.00616.93
8.0.200.0040.00417.11
8.0.190.0030.00517.11
8.0.180.0050.00317.08
8.0.170.0040.00416.90
8.0.160.0000.00717.11
8.0.150.0090.00017.05
8.0.140.0040.00417.03
8.0.130.0030.00313.52
8.0.120.0080.00016.87
8.0.110.0000.00817.03
8.0.100.0040.00416.96
8.0.90.0050.00316.92
8.0.80.0120.00316.91
8.0.70.0000.00716.83
8.0.60.0000.00717.05
8.0.50.0070.00016.98
8.0.30.0110.00617.21
8.0.20.0100.01017.40
8.0.10.0080.00017.13
8.0.00.0080.01016.90
7.4.330.0000.00515.20
7.4.320.0070.00016.63
7.4.300.0080.00016.47
7.4.290.0030.00316.68
7.4.280.0080.00016.65
7.4.270.0030.00316.56
7.4.260.0070.00016.65
7.4.250.0000.00816.50
7.4.240.0020.00516.59
7.4.230.0030.00316.71
7.4.220.0070.01116.50
7.4.210.0070.00716.70
7.4.200.0040.00416.70
7.4.160.0060.01216.70
7.4.150.0100.01017.40
7.4.140.0120.01217.86
7.4.130.0100.01016.58
7.4.120.0090.00916.58
7.4.110.0100.00716.63
7.4.100.0150.00416.64
7.4.90.0040.01516.71
7.4.80.0150.00519.39
7.4.70.0110.00716.88
7.4.60.0110.00716.59
7.4.50.0000.00716.49
7.4.40.0120.00716.52
7.4.30.0070.01716.35
7.4.00.0100.00614.86
7.3.330.0000.00613.30
7.3.320.0000.00613.45
7.3.310.0000.00816.45
7.3.300.0030.00316.36
7.3.290.0100.00916.47
7.3.280.0100.01216.52
7.3.270.0140.00717.40
7.3.260.0060.01816.50
7.3.240.0150.00816.39
7.3.230.0150.00716.46
7.3.210.0060.01216.43
7.3.200.0070.01116.49
7.3.190.0100.00716.52
7.3.180.0060.01116.25
7.3.170.0090.00816.79
7.3.160.0120.00616.42
7.3.10.0030.01016.75
7.3.00.0070.00716.72
7.2.330.0140.00416.94
7.2.320.0140.00716.96
7.2.310.0100.01016.86
7.2.300.0070.01016.84
7.2.290.0180.00616.84
7.2.130.0140.00016.82
7.2.120.0000.01216.98
7.2.110.0100.00716.84
7.2.100.0060.00616.90
7.2.90.0040.00716.76
7.2.80.0030.00616.91
7.2.70.0060.00616.80
7.2.60.0090.00416.79
7.2.50.0090.00616.80
7.2.40.0040.00816.77
7.2.30.0000.01216.96
7.2.20.0060.00917.01
7.2.10.0040.00717.05
7.2.00.0080.00617.97
7.1.250.0060.00315.99
7.1.200.0040.00815.54
7.1.100.0040.00817.55
7.1.70.0040.00416.93
7.1.60.0080.00319.27
7.1.50.0030.01017.02
7.1.00.0130.06322.43
7.0.200.0120.01214.58
7.0.100.0270.04319.99
7.0.90.0170.04019.99
7.0.80.0200.06719.93
7.0.70.0130.07720.00
7.0.60.0030.04019.96
7.0.50.0130.07720.32
7.0.40.0030.04720.13
7.0.30.0100.06320.15
7.0.20.0130.04020.07
7.0.10.0070.07319.99
7.0.00.0100.06320.09
5.6.280.0030.03321.11
5.6.250.0130.07320.55
5.6.240.0100.07720.70
5.6.230.0100.06720.63
5.6.220.0070.04720.68
5.6.210.0130.07720.68
5.6.200.0130.07020.97
5.6.190.0170.03721.01
5.6.180.0130.06721.04
5.6.170.0170.07720.99
5.6.160.0170.07721.10
5.6.150.0070.04721.14
5.6.140.0170.05720.98
5.6.130.0030.09021.07
5.6.120.0070.07021.20
5.6.110.0070.08021.20
5.6.100.0170.07720.95
5.6.90.0130.07721.13
5.6.80.0200.07020.36
5.6.70.0100.07020.54
5.6.60.0130.04020.42
5.6.50.0100.04020.37
5.6.40.0100.05720.45
5.6.30.0070.04320.53
5.6.20.0030.07020.34
5.6.10.0070.05020.42
5.6.00.0130.05320.55
5.5.380.0070.04320.41
5.5.370.0100.05720.44
5.5.360.0130.05020.59
5.5.350.0130.05320.49
5.5.340.0070.08320.96
5.5.330.0000.07320.94
5.5.320.0100.04020.92
5.5.310.0100.04320.81
5.5.300.0000.08320.89
5.5.290.0130.07320.91
5.5.280.0070.05320.68
5.5.270.0070.05020.93
5.5.260.0100.07720.94
5.5.250.0170.05720.64
5.5.240.0000.04320.20
5.5.230.0030.08720.30
5.5.220.0100.08020.31
5.5.210.0030.06320.30
5.5.200.0070.04020.03
5.5.190.0070.04720.16
5.5.180.0070.04720.14
5.5.160.0100.07020.12
5.5.150.0130.05320.11
5.5.140.0130.07020.25
5.5.130.0000.06720.29
5.5.120.0030.06320.21
5.5.110.0030.04320.25
5.5.100.0130.07020.11
5.5.90.0100.04320.08
5.5.80.0130.07320.01
5.5.70.0070.04320.01
5.5.60.0130.06720.09
5.5.50.0100.04320.04
5.5.40.0100.04720.09
5.5.30.0070.05019.96
5.5.20.0070.08020.07
5.5.10.0100.05320.15
5.5.00.0130.07320.08
5.4.450.0130.07719.36
5.4.440.0070.05719.46
5.4.430.0070.07019.48
5.4.420.0030.05019.39
5.4.410.0070.04319.32
5.4.400.0030.07719.10
5.4.390.0130.04019.21
5.4.380.0070.06319.04
5.4.370.0100.07018.85
5.4.360.0070.05719.13
5.4.350.0030.08018.90
5.4.340.0070.06318.85
5.4.320.0130.07319.09
5.4.310.0100.03719.20
5.4.300.0100.07719.05
5.4.290.0000.04318.85
5.4.280.0070.07319.20
5.4.270.0070.04319.18
5.4.260.0000.04719.06
5.4.250.0070.04318.87
5.4.240.0000.04319.02
5.4.230.0100.07319.04
5.4.220.0130.06319.11
5.4.210.0100.07319.13
5.4.200.0170.04719.12
5.4.190.0130.07319.03
5.4.180.0170.07019.15
5.4.170.0130.06018.84
5.4.160.0070.08319.13
5.4.150.0100.07719.18
5.4.140.0130.07016.19
5.4.130.0000.08016.45
5.4.120.0070.03716.40
5.4.110.0070.09316.48
5.4.100.0130.04716.45
5.4.90.0100.05716.38
5.4.80.0070.07316.47
5.4.70.0070.04016.41
5.4.60.0170.05016.27
5.4.50.0030.03716.47
5.4.40.0000.04016.46
5.4.30.0000.04016.32
5.4.20.0030.03316.47
5.4.10.0130.02316.48
5.4.00.0030.03715.83

preferences:
52.4 ms | 400 KiB | 5 Q