相关疑难解决方法(0)

在PHP 7中沉默"声明......应该兼容"警告

升级到PHP 7后,日志几乎因这种错误而窒息:

PHP Warning: Declaration of Example::do($a, $b, $c) should be compatible with ParentOfExample::do($c = null) in Example.php on line 22548

我如何在PHP 7中将这些错误和这些错误静音?

  • 在PHP 7之前,它们是可以轻松处理E_STRICT的警告类型.现在他们只是陈旧的警告.由于我确实想知道其他警告,我不能完全关闭所有警告.

  • 我没有心智能力来重写这些遗留API,甚至没有提及使用它们的所有软件.猜猜看,没人会为此付出代价.我不是首先开发它们所以我不是那个应该责备的人.(单元测试?十年前不是时尚.)

  • 我想,以避免任何欺骗func_get_args和类似尽可能.

  • 我真的不想降级到PHP 5.

  • 我仍然想知道其他错误和警告.

有一个干净,很好的方法来实现这一目标吗?

php-7

63
推荐指数
6
解决办法
3万
查看次数

严格的标准:''应该与...兼容'的声明

我刚刚在PHP 5.4上安装了woocommerce 2.0(在Wordpress上),我得到了这个:

严格标准:WC_Gateway_BACS :: process_payment()的声明应与D:\ my\path\to\htdocs\wordpress\plugins\woocommerce\classes\gateways\bacs\class-wc-gateway中的WC_Payment_Gateway :: process_payment()兼容-bacs.php在线......

我检查文件,发现WC_Payment_Gateway没有方法process_payment().我需要知道如何解决这个问题(不是通过设置error_reporting()).

什么是PHP中的严格标准
在什么条件下我们得到那个错误?

php wordpress woocommerce

19
推荐指数
3
解决办法
6万
查看次数

PHP - 使用不同数量的参数覆盖函数

我正在扩展一个类,但在某些情况下我会覆盖一个方法.有时在2个参数中,有时在3个,有时没有参数.

不幸的是我收到了PHP警告.

我的最小可验证示例:http: //pastebin.com/6MqUX9Ui

<?php

class first {
    public function something($param1) {
        return 'first-'.$param1;
    }
}

class second extends first {
    public function something($param1, $param2) {
        return 'second params=('.$param1.','.$param2.')';
    }
}

// Strict standards: Declaration of second::something() should be compatible with that of first::something() in /home/szymon/webs/wildcard/www/source/public/override.php on line 13

$myClass = new Second();
var_dump( $myClass->something(123,456) );
Run Code Online (Sandbox Code Playgroud)

我收到PHP错误/警告/信息: 错误屏幕

我怎样才能防止这样的错误?

php oop overriding

16
推荐指数
2
解决办法
1万
查看次数

UsersController :: beforeFilter()的声明应与AppController :: beforeFilter(Cake\Event\Event $ event)兼容

我对cakephp ver3.1.3没有经验

我按照说明实现了登录验证功能; http://book.cakephp.org/3.0/en/tutorials-and-examples/blog-auth-example/auth.html

我设法成功蛋糕烘焙我的cakephp v3.1.3应用程序.

我有一个UsersController.php的问题

我从http://book.cakephp.org/3.0/en/tutorials-and-examples/blog-auth-example/auth.html复制并粘贴了以下代码;

public function beforeFilter(Event $event)
{
    parent::beforeFilter($event);
    // Allow users to register and logout.
    // You should not add the "login" action to allow list. Doing so would
    // cause problems with normal functioning of AuthComponent.
    $this->Auth->allow(['add', 'logout']);
} //public function beforeFilter(Event $event)
Run Code Online (Sandbox Code Playgroud)

此代码的存在产生了以下错误;

严格(2048):App\Controller\UsersController :: beforeFilter()的声明应与App\Controller\AppController :: beforeFilter(Cake\Event\Event $ event)兼容[APP/Controller\UsersController.php,第12行]代码上下文包括 - APP/Controller\UsersController.php,第12行Composer\Autoload\includeFile - ROOT\vendor\composer\ClassLoader.php,第412行Composer\Autoload\ClassLoader :: loadClass() - ROOT\vendor\composer\ClassLoader .php,301行spl_autoload_call - [内部],行?? class_exists - [内部],行?Cake\Core\App :: _ classExistsInBase() - CORE\src\Core\App.php,第89行Cake\Core\App :: …

php authentication cakephp cakephp-3.0

7
推荐指数
2
解决办法
5010
查看次数

PHP:"......的声明应与......的声明兼容"

我想为CRUDable(可以保存和删除)的实体创建一个接口.这是我的抽象类:

abstract class AbstractCrudableEntity extends AbstractEntity
{
    abstract public function doSave();
    abstract public function doDelete();
}
Run Code Online (Sandbox Code Playgroud)

我的实现类需要为这些方法添加一些额外的参数.这是实现类的签名:

class Contact extends AbstractCrudableEntity {
    public function doSave(User $user, \UberClientManager $manager);
    public function doDelete(User $user, \UberClientManager $manager);
}
Run Code Online (Sandbox Code Playgroud)

我理解PHP要求实现类与父类具有相同的方法参数(有几个问题可以回答这个问题:例如,这个).所以这不是问题.

但是,我最近在Symfony中遇到了一些处理身份验证令牌的代码.类UsernamePasswordToken延伸AbstractToken,并具有一组不同的参数中__construct()的方法:AbstractToken::__construct()UsernamePasswordToken::__construct().

我的问题是Symfony是如何做到这一点的?这与我的代码有什么区别?

php symfony

4
推荐指数
1
解决办法
2961
查看次数

PayPal_Adaptive :: CURLRequest()的声明应该与PayPal :: CURLRequest()的声明兼容

当我尝试创建invoice时,我收到上述错误.Invoice正在成功创建,但上述错误不会发生.

我发现了这个但它不起作用 - 方法声明应该与PHP 中的父方法兼容这里是函数 -

class PayPal
{
    .
    .
    .
    /**
     * Send the API request to PayPal using CURL
     *
     * @access  public
     * @param   string  NVP string
     * @return  string
     */
    function CURLRequest($Request)
    {
        $curl = curl_init();
                // curl_setopt($curl, CURLOPT_HEADER,TRUE);
                curl_setopt($curl, CURLOPT_VERBOSE, 1);
                curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
                curl_setopt($curl, CURLOPT_TIMEOUT, 30);
                curl_setopt($curl, CURLOPT_URL, $this->EndPointURL);
                curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
                curl_setopt($curl, CURLOPT_POSTFIELDS, $Request);

        if($this->APIMode == 'Certificate')
        {
            curl_setopt($curl, CURLOPT_SSLCERT, $this->PathToCertKeyPEM);
        }

        $Response = curl_exec($curl);       
        curl_close($curl);
        return $Response;   
    }

    . …
Run Code Online (Sandbox Code Playgroud)

php paypal

1
推荐指数
1
解决办法
438
查看次数