严格标准:5.0 方法权限必须兼容 4.0 无权限方法 [英] strict standards: 5.0 method permission must be compatible with 4.0 permissionless method

查看:44
本文介绍了严格标准:5.0 方法权限必须兼容 4.0 无权限方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个扩展 pdf 类的报告生成类.生成报告的类是用 5.0 风格编写的,其中每个方法都有一个权限(publicprivate 等或任何你称之为的).基类是用 4.0 风格编写的,没有 publicprivate 等方法或变量的声明.

I have a report-generating class that extends a pdf class. The report-generating class is written in 5.0 style, where each method has a permission ( public, private, etc or whatever you call it). The base class was written in 4.0 style and doesn't have public, private, etc declaration for methods or variables.

我最近在我们的开发机器上启用了严格的标准,现在我收到了一些错误严格标准:reportPdf::stream()的声明要与Cpdf::stream()的声明兼容

I've recently turned on strict standards on our development machine, and now I'm getting errors that Strict standards: Declaration of reportPdf::stream() should be compatible with that of Cpdf::stream()

但是无论我给 stream() 什么声明,public、private、protected 或根本没有权限,我仍然会收到这个错误.

But no matter what declaration I give to stream(), public, private, protected, or no permission at all, I still get this error.

我能解决这个问题吗?或者我必须在我工作时关闭严格的标准.

Can I fix this? Or must I turn off strict standards while I'm working on this.

迁移到更新的类在这一点上不是一个选择,因为它的功能回报太多了.当关闭严格的标准时,它可以正常工作.

Migrating to a newer class is not an option at this point because it's too much work to for the functionality payoff. It works fine when strict standards are turned off.

我做了一些测试,这是结果矩阵.无论如何,Strict Standards 仍然在抱怨.

I did some testing, and here's the matrix of results. No matter what, Strict Standards still complains.

protected function stream() { ...

Fatal error: Access level to reportPdf::stream() must be public (as in class Cpdf) in

public function stream() { ...

Strict standards: Declaration of reportPdf::stream() should be compatible with that of Cpdf::stream()

私有函数stream() { ...

Fatal error: Access level to reportPdf::stream() must be public (as in class Cpdf)

function stream() { ...

Strict standards: Declaration of reportPdf::stream() should be compatible with that of Cpdf::stream()

还要注意流有 0 个参数,就像它的父类一样 :(

Also note that stream has 0 arguments, just like its parent class :(

推荐答案

如果代码整洁会导致应用程序失败,就没有任何意义.(= 关闭 E_STRICT)

There is no point in code cleanliness if that makes the application fail. (= turn E_STRICT off)

话虽如此,我认为差异肯定在于参数,而不是访问修饰符.PHP 会给出另一个错误.

That being said, I think the discrepancy lies most certainly in the parameters, not in the access modifiers. PHP would give another error else.

stream() 方法在您的派生 reportPdf 类中可能比在 pdf 编写器中具有更多或更少的参数.如果是这样,您可以通过颠倒类的定义顺序来欺骗 PHP.参见 http://bugs.php.net/bug.php?id=46851

The stream() method might have more or fewer arguments in your derived reportPdf class, than in the pdf writer. If so, you can trick PHP by reversing the order in which in the classes are defined. See http://bugs.php.net/bug.php?id=46851

这篇关于严格标准:5.0 方法权限必须兼容 4.0 无权限方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆