Example usage PHP Namespace and Use

Posted on January 11, 2017 at 12:09 am

Pay attention to the order, namespace goes at first line:

namespace LayerShifter\TLDExtract\Tests;
include_once __DIR__ . '/vendor/autoload.php';
use LayerShifter\TLDDatabase\Store;
use LayerShifter\TLDExtract\Exceptions\RuntimeException;
use LayerShifter\TLDExtract\Extract;
use LayerShifter\TLDExtract\Result;
// Below here insert custom functions etc
$extract = new Extract();
$result = $extract->parse('a.b.blogspot.com');

The above example should fix PHP errors like:

PHP Parse error:  syntax error, unexpected 'use' (T_USE) in ...
PHP Fatal error:  Uncaught Error: Class 'Extract' not found in ...

Receive updates via email

Other Posts

Updated Posts