I'm tempted to use interfaces in my project but am unsure if they work with PHP version 5.2 (which I must support).
What is the minimum version of PHP that will allow me to use interfaces in my code?
Interfaces were introduced in php 5! You can see this in the manual here: http://php.net/manual/en/oop5.intro.php
And a quote from there:
Among the features in PHP 5 are the inclusions of visibility, abstract and final classes and methods, additional magic methods, interfaces, cloning and typehinting.
You can also simply test it here: http://3v4l.org/T2uJU and then you see it also there
According to the links on http://php.net/manual/en/migration5.oop.php, interfaces were introduced with PHP version 5.0.
The page "New Functions" under the section "Migrating from PHP 4 to PHP 5.0.x" lists the function get_declared_interfaces()
as being added in PHP 5.0. The same version is listed on the documentation page of the function itself.
The function interface_exists()
was added on PHP 5.0.2 while class_implements()
appeared on PHP 5.1.0.
The standard interfaces Traversable
, Iterator
and some others appeared on PHP 5.0 while Countable
and more specialized iterators appeared on PHP 5.1.0
I think you can safely use interfaces with PHP 5.2.