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();
 
$extract->setExtractionMode(Extract::MODE_ALLOW_ICCAN);
 
$result = $extract->parse('a.b.blogspot.com');
 
print_r($result->getRegistrableDomain());

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

Stay Updated

Other Posts

Updated Posts