Skip to content

Instantly share code, notes, and snippets.

@vertexvaar
Created November 28, 2017 12:14
Show Gist options
  • Save vertexvaar/7471c7a188b9cea96a6754b0af735829 to your computer and use it in GitHub Desktop.
Save vertexvaar/7471c7a188b9cea96a6754b0af735829 to your computer and use it in GitHub Desktop.
<?php
class Accessor
{
public static function getLinkedStaticPropertyIterator($class, $property): \Iterator
{
return (\Closure::bind(
function () use ($class, $property) {
foreach ($class::${$property} as $logger) {
yield $logger;
}
},
null,
$class
))();
}
public static function getStaticProperty($class, $property)
{
return (\Closure::bind(
function () use ($class, $property) {
return $class::${$property};
},
null,
$class
))();
}
public static function &getLinkableStaticProperty($class, $property)
{
$props = &(\Closure::bind(
function &() use ($class, $property) {
$props = &$class::${$property};
return $props;
},
null,
$class
))();
return $props;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment