3v4l.org

run code in 500+ PHP versions simultaneously
<?php class a { public readonly b $b; function __construct(public string $name) { $this->b = new b($this); } function hoohoo(): mixed { return $this->b; } } class b { use weakObjReference; function __construct(a $container) { $this->weakReference($container, 'container'); // $this->container "created" } function heehee($name): mixed { $x = $name . ', '. $this->container->name; return $x; } } $a = new a('world 1'); var_dump($a->hoohoo()->heehee('hello')); // EXAMPLE 1 var_dump((new a('world 2'))->hoohoo()->heehee('good afternoon')); // EXAMPLE 2. trait weakObjReference { // Door containersnt als weak references op te slaan, voorkom je dat container references reference counts verhogen waardoor // cache niet geleegd wordt "want deze instance wordt nog gebruikt". // Ook nuttig bij debugging aangezien bij var_debug c.s. niet het hele object wordt weergegeven // Gebruik: kan gewone eigenschappen vervangen. // $obj->weakReference($containingObject, 'container'); // Vanaf nu bruikbaar: // $obj->container // NOTE: ook bruikbaar voor grandcontainers, sibling containers, etc. protected array $weakObjectStorage = []; protected function weakReference(object $container, string $propertyName='containerc'/*, bool $serializeable=true*/) { $this->weakObjectStorage[$propertyName] = new weakObjReferenceStorage($container); } // Have your own __get? Let it call __getWeakRef() to see if the container is needed function __get(string $propName) { if (! array_key_exists($propName, $this->weakObjectStorage)) { if ( method_exists($this, $propName)) trigger_error("Error in ".__CLASS__. ": unknown property $propName, did you mean the method ".__CLASS__."::$propName() ?", E_USER_ERROR); trigger_error("Error in ".__CLASS__. ": unknown property '$propName'", E_USER_ERROR); } return $this->__getWeakRef($propName); } // Alleen nodig voor in eigen __get() routines function __getWeakRef(string $propName): ?object { if (isset($this->weakObjectStorage[$propName])) { $r = $this->weakObjectStorage[$propName]->get() ; return $r; } return null ; } function __isset(string $propName): bool { return isset($this->$propName) || $this->__issetWeakRef($propName) ; } // Have your own __isset? Let it call __issetWeakRef() to see if it is set as a weak reference function __issetWeakRef(string $propName): bool { return isset($this->weakObjectStorage[$propName]); } private array $temporaryStrongReferences = []; // Temporarily strengthen the reference public function temporaryStrong($property) { if (isset($this->weakObjectStorage[$property])) { $this->temporaryStrongReferences[$property] = $this->weakObjectStorage[$property]->get(); } } // Revert to weak reference public function weakAgain($property) { unset($this->temporaryStrongReferences[$property]); } } class weakObjReferenceStorage { private readonly WeakReference $weakRef; function __construct(object $object) { if ( get_class($object) == 'WeakReference') // VDZ $this->WeakRef = $object; else $this->weakRef = WeakReference::create($object); } public function get(): object { return $this->weakRef->get(); } function __serialize() { // serialize the original object because weakreferences cannot be serialised return ['weakRef'=>$this->weakRef->get()]; } function __unserialize(array $array) { // restore as a weak reference $this->weakRef = WeakReference::create($array['weakRef']); } }

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.5.30.0110.00719.48
8.5.20.0110.00820.14
8.5.10.0090.00116.95
8.5.00.0100.01120.29
8.4.180.0130.01120.08
8.4.170.0110.01020.66
8.4.160.0140.00820.95
8.4.150.0090.00317.01
8.4.140.0110.00918.08
8.4.130.0160.00518.70
8.4.120.0100.00120.57
8.4.110.0100.00720.50
8.4.100.0060.00718.10
8.4.90.0150.00520.52
8.4.80.0060.00322.75
8.4.70.0100.00918.96
8.4.60.0130.00820.57
8.4.50.0120.01020.45
8.4.40.0060.00317.85
8.4.30.0130.00720.55
8.4.20.0040.00421.46
8.4.10.0170.00818.38
8.3.300.0100.01220.88
8.3.290.0130.00920.78
8.3.280.0150.00920.26
8.3.270.0070.01116.67
8.3.260.0100.00716.79
8.3.250.0090.01017.20
8.3.240.0090.01016.79
8.3.230.0100.01016.61
8.3.220.0100.00919.22
8.3.210.0130.00716.65
8.3.200.0050.00516.82
8.3.190.0120.00716.97
8.3.180.0070.00818.82
8.3.170.0150.00317.21
8.3.160.0180.00018.41
8.3.150.0180.00017.22
8.3.140.0030.00616.60
8.3.130.0190.00517.00
8.3.120.0190.00016.61
8.3.110.0150.00316.68
8.3.100.0150.00616.49
8.3.90.0120.00916.50
8.3.80.0230.00016.89
8.3.70.0180.00416.74
8.3.60.0210.00016.56
8.3.50.0190.00316.53
8.3.40.0170.00217.58
8.3.30.0060.01217.66
8.3.20.0160.00317.32
8.3.10.0070.01317.52
8.3.00.0060.00617.56
8.2.300.0130.00720.25
8.2.290.0080.00917.00
8.2.280.0090.01018.55
8.2.270.0100.01016.78
8.2.260.0180.00017.33
8.2.250.0030.00616.66
8.2.240.0140.00516.54
8.2.230.0120.00816.18
8.2.220.0160.00316.83
8.2.210.0150.00616.32
8.2.200.0120.00716.42
8.2.190.0090.00916.45
8.2.180.0120.00616.55
8.2.170.0160.00417.75
8.2.160.0090.00917.73
8.2.150.0060.01317.32
8.2.140.0190.00017.65
8.2.130.0120.00817.39
8.2.120.0170.00317.40
8.2.110.0180.00617.28
8.2.100.0200.00017.45
8.2.90.0130.00717.43
8.2.80.0110.00817.31
8.2.70.0130.00717.35
8.2.60.0150.00417.47
8.2.50.0150.00517.38
8.2.40.0110.00517.59
8.2.30.0090.00917.62
8.2.20.0170.00017.28
8.2.10.0180.00017.65
8.2.00.0120.00617.42
8.1.340.0140.00721.79
8.1.330.0050.00518.13
8.1.320.0120.00716.30
8.1.310.0110.00716.92
8.1.300.0210.00016.39
8.1.290.0140.00616.23
8.1.280.0190.00016.35
8.1.270.0140.00617.27
8.1.260.0120.00917.33
8.1.250.0170.00317.31
8.1.240.0140.00717.13
8.1.230.0180.00017.09
8.1.220.0180.00017.21
8.1.210.0180.00017.09
8.1.200.0140.00617.29
8.1.190.0200.00017.23
8.1.180.0110.00717.25
8.1.170.0160.00317.10
8.1.160.0070.01417.14
8.1.150.0150.00416.90
8.1.140.0140.00417.18
8.1.130.0170.00317.18
8.1.120.0110.00717.14
8.1.110.0150.00417.38
8.1.100.0190.00317.15
8.1.90.0170.00617.06
8.1.80.0080.01017.38
8.1.70.0090.00917.22
8.1.60.0190.00017.42
8.1.50.0160.00317.36
8.1.40.0140.00517.11
8.1.30.0130.00517.25
8.1.20.0160.00217.20
8.1.10.0110.00717.33
8.1.00.0090.00917.05

preferences:
64.06 ms | 1020 KiB | 5 Q