简体   繁体   English

PHP 5.4严格的标准如何使子方法的不同无序参数与父方法兼容?

[英]PHP 5.4 Strict Standards How make disparate, unordered parameters of child method compatible with parent method?

I am debugging a Joomla site, using old Joomla 2.5 . 我正在使用旧版Joomla 2.5调试Joomla网站。 On the move to php 5.4 we encountered the widely discussed strict standards errors. 在转到php 5.4时,我们遇到了广泛讨论的严格标准错误。 Most have been easy to fix. 大多数都易于修复。 I have one last error that is proving more difficult. 我有最后一个错误,事实证明这更加困难。

Strict Standards: Declaration of JCacheControllerView::get() should be compatible with JCacheController::get($id, $group = NULL) in /home/XXXXXX/public_testing/libraries/joomla/cache/controller/view.php on line 137 严格标准:在第137行的/home/XXXXXX/public_testing/libraries/joomla/cache/controller/view.php中,JCacheControllerView :: get()的声明应与JCacheController :: get($ id,$ group = NULL)兼容

Research shows advice such as this: Declaration of Methods should be Compatible with Parent Methods in PHP 研究显示了这样的建议: 方法声明应与PHP中的父方法兼容

JCacheController defines JCacheController定义

public function get($id, $group = null)

JCacheControllerView extends JCacheController and defines: JCacheControllerView扩展了JCacheController并定义了:

public function get(&$view, $method, $id = false, $wrkarounds = true)

So I tried changing the declarations to have the same parameters and same default values: JCacheController defines 因此,我尝试将声明更改为具有相同的参数和相同的默认值:JCacheController定义

public function get($id=false, $group = null, &$view = null, $method = null, $wrkarounds = true)

JCacheControllerView extends JCacheController and defines: JCacheControllerView扩展了JCacheController并定义了:

public function get(&$view = null, $method = null, $id = false, $wrkarounds = true, $group = null)

Which results in: 结果是:

Strict Standards: Declaration of JCacheControllerView::get() should be compatible with JCacheController::get($id = false, $group = NULL, &$view = NULL, $method = NULL, $wrkarounds = true) in /home/freedibl/public_testing/libraries/joomla/cache/controller/view.php on line 137 严格标准:/ home /中的JCacheControllerView :: get()声明应与JCacheController :: get($ id = false,$ group = NULL,&$ view = NULL,$ method = NULL,$ wrkarounds = true)兼容。第137行的freedibl / public_testing / libraries / joomla / cache / controller / view.php

Could this be because the parameters are not in the same order? 难道是因为参数顺序不同? How could I fix this without altering the original method calls? 如何在不更改原始方法调用的情况下解决此问题? Both methods are widely used, and it would be difficult to change every call to either one throughout joomla. 两种方法都被广泛使用,并且在整个joomla中很难将每次调用都更改为任一调用。

The order of parameters doesn't matter for PHP interpreter per se as it doesn't check parameters compatibility by name. 参数的顺序对于PHP解释器本身并不重要,因为它不按名称检查参数的兼容性。 But you have different types of parameters. 但是您有不同类型的参数。 Some of them are references and some are variables - this makes declarations incompatible. 其中一些是引用,一些是变量-这使声明不兼容。

So, you actually can fix this problem by changing the parameters order so the types match in both declarations. 因此,您实际上可以通过更改参数顺序来解决此问题,以便两个声明中的类型都匹配。

Is $view parameter an object or a simple type? $view参数是对象还是简单类型? If it's an object, you probably don't have to pass it as a reference at all. 如果它是一个对象,则可能根本不必将其作为参考传递。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM