3v4l.org

run code in 300+ PHP versions simultaneously
<?php class TestingAccessWrapper { /** @var mixed The object, or the class name for static-only access */ public $object; /** * Return a proxy object which can be used the same way as the original, * except that access restrictions can be ignored (protected and private methods and properties * are available for any caller). * @param object $object * @return TestingAccessWrapper * @throws InvalidArgumentException */ public static function newFromObject( $object ) { if ( !is_object( $object ) ) { throw new InvalidArgumentException( __METHOD__ . ' must be called with an object' ); } $wrapper = new TestingAccessWrapper(); $wrapper->object = $object; return $wrapper; } /** * Allow access to non-public static methods and properties of the class. * Returns an object whose methods/properties will correspond to the * static methods/properties of the given class. * @param string $className * @return TestingAccessWrapper * @throws InvalidArgumentException */ public static function newFromClass( $className ) { if ( !is_string( $className ) ) { throw new InvalidArgumentException( __METHOD__ . ' must be called with a class name' ); } $wrapper = new TestingAccessWrapper(); $wrapper->object = $className; return $wrapper; } public function __call( $method, $args ) { $methodReflection = $this->getMethod( $method ); if ( $this->isStatic() && !$methodReflection->isStatic() ) { throw new DomainException( __METHOD__ . ': Cannot call non-static method when wrapping static class' ); } return $methodReflection->invokeArgs( $methodReflection->isStatic() ? null : $this->object, $args ); } public function __set( $name, $value ) { $propertyReflection = $this->getProperty( $name ); if ( $this->isStatic() && !$propertyReflection->isStatic() ) { throw new DomainException( __METHOD__ . ': Cannot set non-static property when wrapping static class' ); } $propertyReflection->setValue( $this->object, $value ); } public function __get( $name ) { $propertyReflection = $this->getProperty( $name ); if ( $this->isStatic() && !$propertyReflection->isStatic() ) { throw new DomainException( __METHOD__ . ': Cannot get non-static property when wrapping static class' ); } return $propertyReflection->getValue( $this->object ); } /** * Tells whether this object was created for an object or a class. * @return bool */ private function isStatic() { return is_string( $this->object ); } /** * Return a method and make it accessible. * @param string $name * @return ReflectionMethod */ private function getMethod( $name ) { $classReflection = new ReflectionClass( $this->object ); $methodReflection = $classReflection->getMethod( $name ); $methodReflection->setAccessible( true ); return $methodReflection; } /** * Return a property and make it accessible. * * ReflectionClass::getProperty() fails if the private property is defined * in a parent class. This works more like ReflectionClass::getMethod(). * * @param string $name * @return ReflectionProperty * @throws ReflectionException */ private function getProperty( $name ) { $classReflection = new ReflectionClass( $this->object ); try { $propertyReflection = $classReflection->getProperty( $name ); } catch ( ReflectionException $ex ) { while ( true ) { $classReflection = $classReflection->getParentClass(); if ( !$classReflection ) { throw $ex; } try { $propertyReflection = $classReflection->getProperty( $name ); } catch ( ReflectionException $ex2 ) { continue; } if ( $propertyReflection->isPrivate() ) { break; } else { // @codeCoverageIgnoreStart throw $ex; // @codeCoverageIgnoreEnd } } } $propertyReflection->setAccessible( true ); return $propertyReflection; } } class A { private static function func( &$ref ) { $ref = 42; } } $a = TestingAccessWrapper::newFromClass( "A" ); $b = 0; $a->func( &$b ); echo $b;

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.0.80.0120.01216.86
8.0.70.0160.01216.86
8.0.60.0190.00816.75
8.0.50.0130.01016.71
8.0.30.0140.01416.84
8.0.20.0280.01716.88
8.0.10.0170.01016.86
8.0.00.0070.01016.87
7.4.210.0160.01216.46
7.4.200.0140.01116.46
7.4.190.0210.00416.34
7.4.180.0170.01016.50
7.4.160.0200.01016.35
7.4.150.0190.01016.43
7.4.140.0210.00416.16
7.4.130.0150.00816.24
7.4.120.0200.00216.18
7.4.110.0090.01316.29
7.4.100.0140.00916.29
7.4.90.0150.00716.32
7.4.80.0190.00516.27
7.4.70.0080.01616.27
7.4.60.0000.02116.17
7.4.50.0090.01316.02
7.4.40.0070.01716.02
7.4.30.0090.01416.32
7.4.20.0160.00716.16
7.4.10.0180.00416.22
7.4.00.0230.00016.23
7.3.290.0210.00416.18
7.3.280.0210.00416.13
7.3.270.0200.00516.17
7.3.260.0220.00316.12
7.3.250.0220.00316.13
7.3.240.0180.00916.18
7.3.230.0200.01016.05
7.3.220.0210.00716.06
7.3.210.0200.00416.16
7.3.200.0170.01016.14
7.3.190.0150.01316.11
7.3.180.0210.01316.13
7.3.170.0140.01116.02
7.3.160.0180.00716.24
7.3.150.0250.00016.13
7.3.140.0250.00016.02
7.3.130.0150.00916.10
7.3.120.0160.00816.08
7.3.110.0080.01616.00
7.3.100.0350.00516.09
7.3.90.0190.00516.29
7.3.80.0170.00716.04
7.3.70.0080.01516.15
7.3.60.0110.01416.18
7.3.50.0190.00516.28
7.3.40.0120.01216.21
7.3.30.0190.00816.36
7.3.20.0180.00616.21
7.3.10.0310.00216.09
7.3.00.0150.00916.21
7.2.340.0080.01616.14
7.2.330.0120.01216.16
7.2.320.0170.00716.09
7.2.310.0140.01116.21
7.2.300.0160.00915.99
7.2.290.0160.01016.16
7.2.280.0110.01116.05
7.2.270.0190.00616.06
7.2.260.0150.01116.05
7.2.250.0170.01016.06
7.2.240.0250.00416.08
7.2.230.0150.01116.06
7.2.220.0130.01316.02
7.2.210.0160.00916.06
7.2.200.0190.01016.18
7.2.190.0120.01216.25
7.2.180.0170.00716.21
7.2.170.0200.00416.27
7.2.160.0170.00716.34
7.2.150.0230.00516.31
7.2.140.0120.01216.33
7.2.130.0190.00916.43
7.2.120.0170.00916.34
7.2.110.0130.01316.42
7.2.100.0140.01016.41
7.2.90.0180.00616.34
7.2.80.0170.00716.45
7.2.70.0150.01016.37
7.2.60.0220.00316.46
7.2.50.0180.01116.26
7.2.40.0200.01016.32
7.2.30.0200.01016.28
7.2.20.1470.01316.43
7.2.10.0130.01316.36
7.2.00.0210.00416.26
7.1.330.0130.01015.21
7.1.320.0250.00015.18
7.1.310.0210.01015.26
7.1.300.0160.01615.28
7.1.290.0170.00915.36
7.1.280.0250.00715.25
7.1.270.0270.00315.35
7.1.260.0070.01615.17
7.1.250.0230.00015.07
7.1.240.0120.00915.11
7.1.230.0130.01015.20
7.1.220.0230.00015.25
7.1.210.0120.01215.16
7.1.200.0250.00615.22
7.1.190.0210.00715.13
7.1.180.0200.01015.19
7.1.170.0250.00515.16
7.1.160.0200.00715.09
7.1.150.0100.01715.22
7.1.140.0870.00315.25
7.1.130.0150.00815.16
7.1.120.0180.00615.27
7.1.110.0210.00315.22
7.1.100.0150.00915.12
7.1.90.0160.01015.13
7.1.80.0120.01115.14
7.1.70.0240.00415.06
7.1.60.0070.01815.12
7.1.50.0090.01815.10
7.1.40.0130.00915.21
7.1.30.0070.01715.18
7.1.20.0190.00315.08
7.1.10.0110.01115.11
7.1.00.0170.00715.15
7.0.330.0220.00015.00
7.0.320.0150.00914.93
7.0.310.0120.00914.98
7.0.300.0180.00514.83
7.0.290.0160.00814.99
7.0.280.0180.00614.98
7.0.270.0520.00315.00
7.0.260.0180.00514.82
7.0.250.0230.00015.16
7.0.240.0090.01415.05
7.0.230.0110.01115.17
7.0.220.0180.00314.86
7.0.210.0180.00314.87
7.0.200.0170.00514.99
7.0.190.0240.01014.88
7.0.180.0150.00614.87
7.0.170.0190.00314.93
7.0.160.0200.00514.79
7.0.150.0060.01514.93
7.0.140.0090.01314.89
7.0.130.0140.00815.05
7.0.120.0130.01015.07
7.0.110.0220.00014.79
7.0.100.0090.01314.92
7.0.90.0120.01114.97
7.0.80.0140.00914.84
7.0.70.0190.00614.87
7.0.60.0220.00314.90
7.0.50.0130.00914.96
7.0.40.0170.00914.99
7.0.30.0150.01114.92
7.0.20.0150.01114.96
7.0.10.0150.00614.98
7.0.00.0170.00814.87
5.6.400.0140.01115.71
5.6.390.0100.01215.49
5.6.380.0150.00815.56
5.6.370.0150.00715.59
5.6.360.0200.00715.51
5.6.350.0160.01015.71
5.6.340.0130.01315.63
5.6.330.0180.01115.71
5.6.320.0250.00315.70
5.6.310.0200.00315.56
5.6.300.0170.00715.56
5.6.290.0170.00915.55
5.6.280.0070.01615.59
5.6.270.0170.01015.57
5.6.260.0260.00015.51
5.6.250.0220.00715.47
5.6.240.0190.00815.59
5.6.230.0190.00215.67
5.6.220.0110.01115.67
5.6.210.0180.00615.51
5.6.200.0140.01415.75
5.6.190.0150.00915.75
5.6.180.0150.01215.73
5.6.170.0240.00715.81
5.6.160.0100.02015.70
5.6.150.0170.01115.55
5.6.140.0140.01415.65
5.6.130.0180.00915.70
5.6.120.0240.00015.51
5.6.110.0130.01115.57
5.6.100.0140.01115.59
5.6.90.0190.00615.54
5.6.80.0200.00815.68
5.6.70.0230.00315.70
5.6.60.0190.00415.67
5.6.50.0170.00915.59
5.6.40.0130.01215.52
5.6.30.0180.01115.64
5.6.20.0190.00915.50
5.6.10.0180.00715.46
5.6.00.0130.01015.60
5.5.380.0190.00715.63
5.5.370.0140.00815.82
5.5.360.0110.01115.56
5.5.350.0110.01115.54
5.5.340.0090.01415.43
5.5.330.0150.00915.51
5.5.320.0160.01015.36
5.5.310.0150.01115.42
5.5.300.0270.00615.43
5.5.290.0150.01515.40
5.5.280.0140.00915.39
5.5.270.0150.00815.52
5.5.260.0140.00915.59
5.5.250.0120.01415.62
5.5.240.0150.01015.53
5.5.230.0170.00415.54
5.5.220.0090.01215.65
5.5.210.0200.00315.57
5.5.200.0250.00315.42
5.5.190.0110.01415.45
5.5.180.0080.01315.41
5.5.170.0160.00615.40
5.5.160.0100.01315.34
5.5.150.0130.01315.34
5.5.140.0130.01315.22
5.5.130.0060.01515.25
5.5.120.0170.00615.23
5.5.110.0040.01815.28
5.5.100.0130.01515.50
5.5.90.0040.01715.46
5.5.80.0120.00915.49
5.5.70.0150.01215.55
5.5.60.0110.01115.50
5.5.50.0110.01115.48
5.5.40.0140.00715.39
5.5.30.0160.00615.67
5.5.20.0170.00715.48
5.5.10.0120.01215.52
5.5.00.0070.01815.48
5.4.450.0120.00512.46
5.4.440.0060.01212.45
5.4.430.0160.00412.45
5.4.420.0120.00612.46
5.4.410.0040.01312.45
5.4.400.0130.00412.38
5.4.390.0060.01112.41
5.4.380.0080.00812.39
5.4.370.0100.00712.31
5.4.360.0140.00312.37
5.4.350.0130.00412.26
5.4.340.0100.00712.37
5.4.330.0130.00412.31
5.4.320.0120.00612.48
5.4.310.0080.01512.32
5.4.300.0140.00512.39
5.4.290.0030.01412.42
5.4.280.0070.01012.45
5.4.270.0200.00012.37
5.4.260.0190.00012.38
5.4.250.0080.00812.41
5.4.240.0120.00412.27
5.4.230.0140.00212.14
5.4.220.0080.01512.20
5.4.210.0100.00712.21
5.4.200.0100.00712.20
5.4.190.0100.01012.09
5.4.180.0140.00412.22
5.4.170.0100.00712.25
5.4.160.0100.00712.26
5.4.150.0040.01312.18
5.4.140.0080.01012.36
5.4.130.0140.00312.45
5.4.120.0140.00412.43
5.4.110.0060.01412.41
5.4.100.0140.00412.44
5.4.90.0130.00312.41
5.4.80.0100.00712.47
5.4.70.0150.00612.52
5.4.60.0140.00412.50
5.4.50.0090.00912.37
5.4.40.0120.00612.26
5.4.30.0120.00912.38
5.4.20.0140.00612.46
5.4.10.0130.00812.45
5.4.00.0090.01312.27
5.3.290.0120.00413.26
5.3.280.0130.00713.04
5.3.270.0120.00813.09
5.3.260.0100.00813.24
5.3.250.0070.01113.25
5.3.240.0140.00313.23
5.3.230.0180.00413.18
5.3.220.0090.01413.04
5.3.210.0110.00912.91
5.3.200.0280.00612.91
5.3.190.0090.01312.99
5.3.180.0110.00913.16
5.3.170.0130.00613.09
5.3.160.0150.00613.25
5.3.150.0050.01513.25
5.3.140.0140.00713.18
5.3.130.0140.00513.11
5.3.120.0140.00313.16
5.3.110.0150.00313.18
5.3.100.0140.00313.06
5.3.90.0110.00713.32
5.3.80.0170.00013.09
5.3.70.0130.00513.25
5.3.60.0060.01613.22
5.3.50.0140.00513.02
5.3.40.0170.01213.03
5.3.30.0070.01113.06
5.3.20.0080.01113.13
5.3.10.0090.00913.00
5.3.00.0140.00712.95
5.2.170.0150.00012.18
5.2.160.0060.01212.07
5.2.150.0120.00312.18
5.2.140.0070.01011.98
5.2.130.0100.00512.02
5.2.120.0130.00312.24
5.2.110.0000.01411.96
5.2.100.0090.00611.98
5.2.90.0070.00712.04
5.2.80.0080.00812.05
5.2.70.0120.00311.93
5.2.60.0030.01111.84
5.2.50.0070.00712.05
5.2.40.0080.00511.98
5.2.30.0060.00911.88
5.2.20.0070.00711.91
5.2.10.0110.00211.82
5.2.00.0050.00811.76
5.1.60.0150.00311.05
5.1.50.0120.00611.26
5.1.40.0040.00911.10
5.1.30.0110.00411.30
5.1.20.0030.01011.08
5.1.10.0050.00811.23
5.1.00.0070.00711.18
5.0.50.0090.00210.52
5.0.40.0000.01210.52
5.0.30.0060.00610.52
5.0.20.0090.00310.52
5.0.10.0000.01110.52
5.0.00.0100.00010.52
4.4.90.0040.00410.52
4.4.80.0070.00010.52
4.4.70.0030.00310.52
4.4.60.0060.00010.52
4.4.50.0030.00310.52
4.4.40.0090.00010.52
4.4.30.0050.00510.52
4.4.20.0030.00410.52
4.4.10.0000.00710.52
4.4.00.0060.00310.52
4.3.110.0060.00010.52
4.3.100.0060.00010.52
4.3.90.0020.00410.52
4.3.80.0050.00210.52
4.3.70.0030.00310.52
4.3.60.0060.00010.52
4.3.50.0000.00710.52
4.3.40.0030.00310.52
4.3.30.0050.00010.52
4.3.20.0000.00510.52
4.3.10.0000.00610.52
4.3.00.0050.00010.52

preferences:
41.17 ms | 451 KiB | 5 Q