Talk in English - US at PHPBenelux Conference 2018
View Slides: https://www.slideshare.net/MarkBakerUK/anonymous-classes-behind-the-mask
Short URL: https://joind.in/talk/a7481 (QR-Code (opens in new window))
One of the most recent new features of PHP is Anonymous Classes, introduced with PHP version 7.
But what are Anonymous Classes? How do you use them? And what would you use them for? Let’s take a look behind the mask, and find out.
Anonymous Classes were introduced to PHP7 with very little fanfare, and without much explanation of the use cases where they might have value. Yet they have the potential to be extremely useful in a whole range of situations from internal classes within libraries, to creating mocks for unit testing; but only if developers are aware of them, and understand how to use them, and what limitations there are to using them.
A central part of this talk will look at how Anonymous Classes can be used as an alternative to stubs and mocks in unit testing, and how assertions like
can be simulated; and how to use Anonymous classes to unit test abstract classes and traits.
Another part will include my investigations into an Anonymous Class Factory with additional information about creating Inner/Nested Anonymous classes.