Skip to content

Runtime-created, type-checked Collections objects in PHP.

License

Notifications You must be signed in to change notification settings

Duroth/magic_collection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

duroth/magic_collection

"The best idea I've ever had."

This library enables runtime creation of type-safe object collections through the amazing technique known as eval().

Need to store a set of DateTimeImmutable instances, but you're too lazy to write your own DateTimeImmutableCollection? With Magic (Collection), you don't need to! Just create and register the Magic Autoloader, and you're done!

Don't believe me? Just watch!

<?php

// Step 1 of 1: Create and register the autoloader. Yes, you can invoke it as a functon.
$magicCollectionLoader = new \Duroth\Magic\Autoloader();
spl_autoload_register($magicCollectionLoader);

// Ta-da! Your new Collection is usable, just like that!
$dates = new \DateTimeImmutableCollection([ new DateTimeImmutable() ]);

// It's automatically typed, and raises exceptions on any invalid data!
$noGood = new \DateTimeImmutableCollection([ new DateTime() ]); // EXCEPTION!

// Works with just about every class, even your own!
$foos = new \Your\Silly\FooClassCollection([
    new \Your\Silly\FooClass(1),
    new \Your\Silly\FooClass(2),
]);

Disclaimer

The above is sarcasm. This project is a joke.

Although the concept does actually work, this library is intended as a stupid little joke, and should not be used in any serious projects. It's a wonderful display of horrible antipatterns, and a great example of how not to do things. Let that be all this is.

About

Runtime-created, type-checked Collections objects in PHP.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages