In this page:
The framework has its own autoloader implementation which follows PSR-4 in almost all aspects of autoload. There are some differences which are:
ClassLoaderException
if a class was not found.
vendorName\subNamespaceNames\ClassName
(names uses camleCase).
The framework can be configured to not throw an exception. This can be performed during the process of initializing the autoloader AutoLoader .
Recommended coding style is driven from PHP's recommended style and PSR, but it does not strictly follow it. For this reason, there are few differences. The rules are divided into two types, styles that must always be followed and recommended styles.
<?php
instead of
<?
for PHP tags.
echo
command (e.g.
<?= 'A a string' ?>
instead of
<?php echo 'A a string' ?>
).
lower\case
.
ALL_CAPS
.
Code
define('MY_CONST', 44);
const CLASS_CONSTANT = 44;
camelCase
.
Code
class Hello {
private $fullName;
private $email;
public function helloWorld() {
}
}
PascalCase
.
Code
class HelloWorldClass {
public static $HelloString;
}
{
must be on the same line for functions, method and class declaration.
elseif
. Always use
else if
.
use webfiori\MyClass as XYZ
).
static
or/then
final
.
Code
public static final function myFunc() {
}
===
or
!==
) when comparing
bool
or
null
.
empty()
to check for
null
values.
isset()
Code
//Wrong
$nextLine = isset($traceEntry['line']) ? $traceEntry['line'] : 'X';
//Accepted
$nextLine = $traceEntry['line'] ?? 'X';
class XXXTest {
}
Code
In this context, the `XXX` should be replaced by entity name that test class represent. (e.g. `GenerateReportTest`).
* Name of test methods should always follow this syntax:
``` php
public function testXXX00() {
}
In this context, the
XXX
should be replaced by functionality name that test class represent. (e.g.
public function testGetData00{}
).
@test
annotation should be included on top of every test method.
The PHPDoc block must be similar to the following style:
Code
/**
* SHORT_DESC.
*
* LONG_DESC.
*
* @annotation1 DETAILS
*
* @annotation2 DETAILS
*/
Where:
SHORT_DESC
is a short description of the class or method. Must be ended by a dot.
LONG_DESC
is a big paragraph that contains more details.
@annotation1
and
@annotation2
are simple PHPDoc annotations such as
@return
or
@param
.
Notice that each part of the doc block must be followed by an empty space. This helps in improving readability.