skip to Main Content
PHP Strict Standards:  Declaration Of A Should Be Compatible With B

We bumped into an PHP Strict standards: Declaration of A should be compatible with B issues.We had a theme made by us quite some time stop working recently.  One we we were using as a demo mainly. So we decided to work things out. As many of you might bump into this I decided to jot this down.

Strict Coding Standards Warning

The warning we got was:

Declaration of THeaderContainer::OnEnableEvent($Sender, $Input) should be compatible with TControl::OnEnableEvent($Sender)

This is a strict coding standards warning. See comment searching this PHP.net page for declaration. The first argument does have two arguments, but the second does not. This could be fixed using:

OnCreateEvent($Sender, $input)

with the extra argument $input added. This had to be done across like 35 files so I had to do a search and replace.

Additional Similar Declaration warning

The same had to be done with:

OnEnableEvent($Sender)

occurrences. This to deal with warnings like:

Warning: Declaration of THeaderContainer::OnEnableEvent($Sender, $Input) should be compatible with TControl::OnEnableEvent($Sender) in /../../../../../THeaderContainer.php on line 32

So just like with the previous warning we added the extra argument $input to make PHP in Strict Mode happy.

Cause

The main question remains though why this pops up now though. We had been running PHP 7.0 for quite some time already so been using a post PHP 5.4 version for quite some time to say the least. And we did see some errors from time to time, but now we could no longer login. What had changed is that we moved from a VPS to Dreamhost shared hosting so perhaps lack of memory spoiled the party.

Strict Mode needed?

You do of course not need to work with PHP Strict Mode and you can turn it off. This by changing php.ini, or a user.ini. or removing or adjusting mode declarations in other files. But as we had this project up and running with it since way back I decided to stick to this. And this way you do learn a lot about PHP and how to write it properly.

Advertisements

Jasper Frumau

Jasper has been working with web applications such as Joomla!, Magento and his favorite WordPress for more than a decade. He helps customers with webdesign and online marketing. Services provided are webdesign, ecommerce, SEO, content marketing. When Jasper is not coding, marketing a website, reading about the web or dreaming the internet of things he plays with his son, travels or run a few blocks.

Leave a Reply

Back To Top