2010-10-22 96 views
1

错误:错误在PHP代码

Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE in 
PSubscriptionFile.php on line 90; 

我认为公共静态_fromJSON应该是公开的

static function _fromJSON 

但给予致命错误:

Declaration of PSubscriptionFile::__construct() must be compatible with that of 
PuSHSubscriptionInterface::__construct() in PSubscriptionFile.php on line 9 

的文件:http://github.com/bobdia/PuSHSubscriber

我不明白如何解决这个错误。谢谢!

+3

90行是空的r github文件。请在这里复制+粘贴相关代码(前后90行+3行) – 2010-10-22 10:46:31

回答

12

你写

public static _fromJSON($data) { 

,而不是

public static function _fromJSON($data) { 

致命错误,当你解决这个问题是因为你的构造函数的签名是不相同的构造函数签名由interfacePuSHSubscriptionInterface要求,你就会得到它定义在您的底部PuSHSubscriber.php

public function __construct(
    $domain, $subscriber_id, $hub, 
    $topic, $secret, $status = '', 
    $callback_url, $verify_token, $lease_time=''); 

,而你是

public function __construct(
    $domain, $subscriber_id, $hub, 
    $topic, $secret, $status = '', 
    $callback_url, $verify_token, $lease_time) 

你需要做的最后一个参数。 The note in the PHP Manual明确表示:

The class implementing the interface must use the exact same method signatures as are defined in the interface. Not doing so will result in a fatal error.

接口的要点是有合同。实现这个契约的类不能改变接口定义的方法签名,因为这会破坏契约并破坏接口的目的。

当接口IFoo说,你应该有

public function fn($arg1, $arg2, $arg3 = NULL); 

然后实施IFoo每类必须实现的接口中定义的方法。

1

我只是做了一些跟进提到的问题。

  1. 原始源代码 “PSubscriptionFile.php”(HERE)尝试90. 线的误差可以修改

    public static _fromJSON($data) { 
    

    public static function _fromJSON($data) { 
    
  2. 然后,如建议由Gordon修改“PSubscriptionFile”的第35行。PHP的”

    public function __construct($domain, $subscriber_id, $hub, $topic, $secret, $status = '', $callback_url, $verify_token, $lease_time) { 
    

    来(看线的末端)现在

    public function __construct($domain, $subscriber_id, $hub, $topic, $secret, $status = '', $callback_url, $verify_token, $lease_time='') { 
    
  3. ,你可能会看到错误消息(可能会略有不同)

    Warning: file_put_contents(./subscriptions/example_subs/1.pubsub) [function.file-put-contents]: failed to open stream: No such file or directory in C:\www\pubsub\PSubscriptionFile.php on line 52 
    

    *注:假设所有的文件都放入目录“pubsub”,目录“www”是Apache服务器的目录。

    这是告诉你,你需要一个包含所有* .pubsub文件的目录。 所以,看看你的源代码文件“的index.php”(HERE)在24线 的代码显示该目录的名称应为“example_subs”

    $domain = 'example_subs'; 
    

    然后,创建“example_subs”空目录C:\ www \ pubsub \ example \ subscriptions

    最后,在订阅之后,您会在目录C:\ www \ pubsub \中找到一个名为NUMBER.pubsub(例如:1.pubsub)示例\ subscriptions \ example_subs