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.