Message (4)

Error: E_WARNING

Description: Run-time warning.

Message: Trying to access array offset on value of type null

Stack Trace:

#0 At webfiori\framework\ui\ErrorBox Line 614

#1 At webfiori\framework\WebFioriApp Line 193

#2 At webfiori\examples\views\MdPage Line 109

#3 At webfiori\examples\views\MdPage Line 44

#4 At app\ini\routes\PagesRoutes Line

#5 At Router Line 1436

#6 At webfiori\framework\router\Router Line 1540

#7 At webfiori\framework\router\Router Line 1398

#8 At webfiori\framework\router\Router Line 691

#9 At webfiori\framework\router\Router Line 56

#10 At webfiori\Index Line 83

#11 At webfiori\Index Line 87

Tip: To display more details about the error, define the constant "WF_VERBOSE" and set its value to "true" in the class "GlobalConstants".

Coding Standards of WebFiori Framework | WebFiori
WebFioriAPI ReferenceLearnDownloadContributeLearn{{result.parent_page}} > {{result.title}}{{result.title}}Classes{{result.class_name}}{{result.summary}}Methods{{result.name}}{{result.summary}}

Coding Standards of WebFiori Framework

In this page:

Autoload

The framework has its own autoloader implementation which follows PSR-4 in almost all aspects of autoload. There are some differences which are:

  • The autoloader will throw ClassLoaderException if a class was not found.
  • It is recommended that a fully qualified class name to have the following form: 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.

Coding Style

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.

Must Follow

  • Always use <?php instead of <? for PHP tags.
  • In case of templates, use the short-hand echo command (e.g. <?= 'A a string' ?> instead of <?php echo 'A a string' ?>).
  • Namespaces must be all lower\case.
  • Class constants and global constants names must be declared in ALL_CAPS.

Code

123
define('MY_CONST', 44);
const CLASS_CONSTANT = 44;
  • Methods names, non-static class attributes must be declared in camelCase.

Code

1234567
class Hello {
    private $fullName;
    private $email;
    public function helloWorld() {
    }
}
  • Classed names, static attributes names must be declared in PascalCase.

Code

1234
class HelloWorldClass {
    public static $HelloString;
}
  • An opening braces { must be on the same line for functions, method and class declaration.
  • Never use elseif. Always use else if.
  • Always include access modifiers for class methods, even if they are public.
  • Do not use aliases for imported classes or class constants (e.g. use webfiori\MyClass as XYZ).
  • Method names and attributes must be defined as follows, first include access modifier followed by static or/then final.

Code

123
public static final function myFunc() {
}
  • For comparison, always use strict comparison (=== or !==) when comparing bool or null.
  • Do not use the construct empty() to check for null values.
  • Use 'null coalescing operator' when needing to use a ternary in conjunction with isset()

Code

123456
//Wrong
$nextLine = isset($traceEntry['line']) ? $traceEntry['line'] : 'X';

//Accepted
$nextLine = $traceEntry['line'] ?? 'X';

Recommendations

  • Always place PHP code in classes.
  • Always specify method parameter's data type.
  • Always specify method's return type.

Unit Tests Style

  • The name of test classes should always follow this syntax:
    
    class XXXTest {

}

Code

1234567
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.

Documentation Style

The PHPDoc block must be similar to the following style:

Code

12345678910
/**
 * 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.

View this page on GitHubLast modified: 1970-01-01 03:00:00
Powered By: WebFiori Framework, Vue and VuetifyAll Rights Reserved © 2018 - 2024