Skip to content

Instantly share code, notes, and snippets.

@mindplay-dk
Created March 10, 2016 11:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mindplay-dk/d4afeb52086b7205ffc7 to your computer and use it in GitHub Desktop.
Save mindplay-dk/d4afeb52086b7205ffc7 to your computer and use it in GitHub Desktop.
class or object???
<?php
// anonymous classes are both instances and types. huh? what?
$type = new class {
public function foo() {
echo "YAY";
}
};
$type->foo(); // => "YAY"
$object = new $type();
$object->foo(); // => "YAY"
@orolyn
Copy link

orolyn commented Mar 21, 2016

Lol, it's a class, just like any other but without a name.
What u are seeing is an object being instantiated from another object.

Try $type = new DateTime();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment