For a project assigned to me, I have to stick to following the PSR coding standard for PHP. Now, I am having a hard time understanding one thing.
Is the following PSR-1 and PSR-12 compliant?
<?php
// A.php
abstract class A
{}
<?php
// B.php (in the same directory as A.php)
include 'A.php';
class B extends A
{}
In B.php
, I am directly including the file A.php
. Is this alright? Or does the standard require us to use the use
keyword instead, and to leave the rest of the job to PHP's autoloading mechanism, as shown below:
<?php
// A.php
namespace Classes\A;
abstract class A
{}
<?php
// B.php (in the same directory as A.php)
namespace Classes\B;
use Classes\A;
class B extends \Classes\A
{}
The problem is that the specification does not state it in clear-cut words that we MUST use classes and namespaces instead of classes and include
s (or require
s, for that matter). That's why I am confused as to what to do here.