PHP notes

PHP

PHP key concepts.

Namespace


<?php
namespace App\Controllers\Admin;

Class MyController{
	//...
}

?>

Then in another class, we could use App\Cpontrollers\Admin\AuthController.

For Laverel

$ composer dump-autoload

Use


from use3.php.net

<?php
namespace foo;

use My\Full\Classname as Another;

// this is the same as use My\Full\NSname as NSname
use My\Full\NSname;

// importing a global class
use ArrayObject;

// importing a function (PHP 5.6+)
use function My\Full\functionName;

// aliasing a function (PHP 5.6+)
use function My\Full\functionName as func;

// importing a constant (PHP 5.6+)
use const My\Full\CONSTANT;

$obj = new namespace\Another; // instantiates object of class foo\Another

$obj = new Another; // instantiates object of class My\Full\Classname

NSname\subns\func(); // calls function My\Full\NSname\subns\func

$a = new ArrayObject(array(1)); // instantiates object of class ArrayObject
// without the "use ArrayObject" we would instantiate an object of class foo\ArrayObject

func(); // calls function My\Full\functionName

echo CONSTANT; // echoes the value of My\Full\CONSTANT
?>

Array vs SplObjectStorage


SplObject is good for storing object as an element of the set, or as a key to map. And according to the benchmark from Matt Butcher , it surpasses the Array when it comes to mapping the objects.