note 111585 added to function.class-alias

From: Date: Wed, 06 Mar 2013 14:05:30 +0000
Subject: note 111585 added to function.class-alias
Groups: php.notes 
Request: Send a blank email to php-notes+get-193957@lists.php.net to get a copy of this message
class_alias() gives you the ability to do conditional imports. Whereas the following will not work: <?php namespace Component; if (version_compare(PHP_VERSION, '5.4.0', 'gte')) { use My\ArrayObject; } else { use ArrayObject; } class Container extends ArrayObject { } ?> the following, using class_alias, will: <?php namespace Component; if (version_compare(PHP_VERSION, '5.4.0', 'lt')) { class_alias('My\ArrayObject', 'Component\ArrayObject'); } else { class_alias('ArrayObject', 'Component\ArrayObject'); } class Container extends ArrayObject { } ?> The semantics are slightly different (I'm now indicating that Container extends from an ArrayObject implementation in the same namespace), but the overall idea is the same: conditional imports. ---- Server IP: 69.147.83.199 Probable Submitter: 208.107.183.205 ---- Manual Page -- http://php.net/manual/en/function.class-alias.php Edit -- https://master.php.net/note/edit/111585 Del: integrated -- https://master.php.net/note/delete/111585/integrated Del: useless -- https://master.php.net/note/delete/111585/useless Del: bad code -- https://master.php.net/note/delete/111585/bad+code Del: spam -- https://master.php.net/note/delete/111585/spam Del: non-english -- https://master.php.net/note/delete/111585/non-english Del: in docs -- https://master.php.net/note/delete/111585/in+docs Del: other reasons-- https://master.php.net/note/delete/111585 Reject -- https://master.php.net/note/reject/111585 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#193957) next »