PHP Use Keyword Namespace Not Finding Class -
weirdness. ideas why can't find class?
directory tree:
test2.php - src - google - spreadsheet defaultservicerequest.php servicerequestinterface.php google_client.php ... test2.php:
namespace src\google\spreadsheet; require_once 'src/google/spreadsheet/servicerequestinterface.php'; require_once 'src/google/spreadsheet/defaultservicerequest.php'; require_once 'src/google/spreadsheet/google_client.php'; use google\spreadsheet\servicerequestinterface; use google\spreadsheet\defaultservicerequest; use google\spreadsheet\servicerequestfactory; function getgoogletokenfromkeyfile($clientid, $clientemail, $pathtop12file) { require 'src/google/spreadsheet/google_client.php'; $client = new google_client(); $client->setclientid($clientid); $cred = new google_auth_assertioncredentials( $clientemail, array('https://spreadsheets.google.com/feeds'), file_get_contents($pathtop12file) ); $client->setassertioncredentials($cred); if ($client->getauth()->isaccesstokenexpired()) { $client->getauth()->refreshtokenwithassertion($cred); } $service_token = json_decode($client->getaccesstoken()); return $service_token->access_token; } $servicerequest = new defaultservicerequest(getgoogletokenfromkeyfile(..., ..., ...)); servicerequestfactory::setinstance($servicerequest); not sure if google api related or what. weird servicerequest classes wouldn't work until required them. when didn't, said couldn't find it... , when tried adding src/ use path, didn't work, , tried removing path together, did nothing.
error: fatal error: class 'src\google\spreadsheet\google_client' not found in test2.php on line 15
looks using this library
if used composer install library need include vendor/autoload.php file in code
require 'vendor/autoload.php'; it recomneded use composer install library if don't want use composer, need create autoloader , require in code
Comments
Post a Comment