Showcase: The create() function

at 2007-05-06 in Examples by friebe (0 comments)

As a side product of RFC #0106, the create() core functionality, which is used to create generic objects, provides an overloaded variant of itself: When passed an object, it will return it.

This may seem a bit strange (and kind of useless) in the first moment, but actually solves a deficit in the PHP parser, which does not allow chaining after new:

<?php 
$c= new Criteria()->add('author_id', 501, EQUAL); // Parse error
?>

By using create(), we can work around this as follows:
<?php 
$c= create(new Criteria())->add('author_id', 501, EQUAL);
?>



Subscribe

You can subscribe to the XP framework's news by using RSS syndication.


Categories

News
General
PHP5
Announcements
RFCs
Further reading
Examples
Editorial
EASC
Experiments
Unittests
Databases

Related

Find related articles by a search for «Showcase:».