3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Test { public function getAssociations(array $including = null, array $types = ['hasOne', 'belongsTo', 'hasMany', 'hasAndBelongsToMany']) { // Associations do not store any state, only instanciate once per model base class static $associations = []; $result = []; foreach ($types as $type) { foreach ($this->{$type} as $name => $properties) { if ($including !== null and !isset($including[$name]) and !in_array($name, $including, true)) { continue; } if (!isset($associations[$name])) { $class = 'Model_Association_' . ucfirst($type); $associations[$name] = new $class( $this, $name, $properties ); } $result[$name] = $associations[$name]; } } return $result; } } ?>

preferences:
43.84 ms | 402 KiB | 5 Q