为什么在包含了正确的名称空间之后还会出现致命错误


Why the fatal error is coming even after including proper namespaces?

下面是我使用php-pushwoosh库编写的发送推送通知的程序:

<?php
ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(-1);
use Gomoob'Pushwoosh'Client'Pushwoosh;
use Gomoob'Pushwoosh'Model'Request'CreateMessageRequest;
use Gomoob'Pushwoosh'Model'Notification'Notification;
use Gomoob'Pushwoosh'Exception;
require __DIR__.'/vendor/autoload.php';
/*require('../config.php');
require('../common.php');*/
$data = json_decode(file_get_contents('php://input'), true);
$auth_token = $data['auth_token'];
$app_code   = $data['app_code'];
$page_no    = $data['page_no'];
$page_total = $data['page_total'];
define('PW_AUTH', $auth_token);
define('PW_APPLICATION', $app_code);
// Create a Pushwoosh client
$pushwoosh = Pushwoosh::create()
    ->setApplication(PW_AUTH)
    ->setAuth(PW_APPLICATION);
if(!empty($page_no) && !empty($page_total)) {
  if (!Phpfox::isUser()) {
    $flag = false;
    $response["error"] = "error";
    $response["message"] = "Please login";
    echoRespnse(401, $response);
  } else {    
    $notificaions = Phpfox::getService('notification')->getAllNotifications($page_no,$page_total);
    if(!empty($notificaions)) {
      $notificaions = walk_recursive_remove($notificaions, 'unset_null_children');
      for($i=0;$i<count($notificaions);$i++) {
        $notificaions[$i]['message'] = stripslashes(strip_tags($notificaions[$i]['message']));
        $notificaions[$i]['profile_image'] = image_creator($notificaions[$i]['user_image']);
      }
      $notifications_data = json_encode($notifications);      
    } 
  }  
} else {
  $notifications_data = "Error in request";
}   
// Create a request for the '/createMessage' Web Service
$request = CreateMessageRequest::create()
    ->addNotification(Notification::create()->setContent($notifications_data));
// Call the REST Web Service
$response = $pushwoosh->createMessage($request);
// Check if its ok
if($response->isOk()) {
  print 'Great, my message has been sent !';
} else {
  print 'Oops, the sent failed :-( '; 
  print 'Status code : ' . $response->getStatusCode()." ";
  print 'Status message : ' . $response->getStatusMessage();
}
?>

在服务器上执行后,我得到以下致命错误:

Fatal error: Uncaught exception 'Gomoob'Pushwoosh'Exception`'PushwooshException' with message 'None of the 'application' or 'applicationsGroup' properties are set !' in /var/www/api/gomoob-php-pushwoosh/vendor/gomoob/php-pushwoosh/src/main/php/Gomoob/Pushwoosh/Client/Pushwoosh.php:106 Stack trace: #0 /var/www/api/gomoob-php-pushwoosh/push_notifications.php(61): Gomoob'Pushwoosh'Client'Pushwoosh->createMessage(Object(Gomoob'Pushwoosh'Model'Request'CreateMessageRequest)) #1 {main} thrown in /var/www/api/gomoob-php-pushwoosh/vendor/gomoob/php-pushwoosh/src/main/php/Gomoob/Pushwoosh/Client/Pushwoosh.php on line 106`

如果你想要查看我所包含的命名空间的层次结构,你可以查看php-pushwoosh命名空间层次结构

您在这一行遇到了问题,因为PW_AUTH &未定义PW_APPLICATION

// Create a Pushwoosh client
$pushwoosh = Pushwoosh::create()
    ->setApplication(PW_AUTH)
    ->setAuth(PW_APPLICATION);

必须定义PW_AUTH &PW_APPLICATION常量,也必须交换它,对于setAuth使用PW_APPLICATION