A massive BC break

So when you query your database and the connection had failed, you expect it should work anyway, because you should weakly convert false to a database object? That’s definitely what PHP does, right? No? Oh… so the Query command strongly types its database parameter? It cant be! I didnt turn strict typing on!
If i say $n = 3; $n[1] = "wark";, that should work, right? Weak typing! turn it into an array! What? No? oh…

It’s always been there. They didnt enforce it on everything, but its always been there. The RFC’s you cite in your article dont say “every in-built PHP function must have all parameters weakly typed”, it says some variation on “IF they are weakly typed, then the system must accept and coerce weakly.”

And if PHP is moving towards strict typing, or as was put in your opening post, have decided to “Change the behviour to match the documentation”… that’s what PHP has decided to do. Closing what, based on the documentation, is a bug. Just because you wrote your code based on what is now deemed a bug doesnt make their decision wrong.

You updated to a new MAJOR version of a piece of software and didnt check to see if something broke. shrug

I’m hoping that they add an option in php.ini to globally enforce strict typing rather than having to declare it in every script


Your example showing bad code that no-one would ever use is a joke. It shows that you clearly don’t understand how weak typing has worked for the past 20 years. Although it allows you to pass anything as a parameter it’s value is checked within the function to see if it is the correct type or can be converted to the correct type. If not it is rejected. Strict typing means that the value’s type is checked by the PHP engine BEFORE it is passed to the function using the type hint for that parameter in the function’s signature.

Weak typing has been the default since PHP was created. It says so in the documentation. It has always coerced NULL into either an empty string or the value zero depending on the context. It says so in the documentation. Strict typing is supposed to be an option which is OFF unless it is specifically turned ON.

The changes made in version 8 are a complete reversal of 20 years’ tradition. They are not improving the language, they are destroying it. People are not upgrading to the latest version simply because their code, which has worked for years, suddenly stops working. It is not THEIR code which is broken, it is PHP itself.

Closing what, based on the documentation, is a bug.

It was not a bug. All the internal functions worked AS DOCUMENTED, which was in weak typing mode. The function signature for the abs() function used to read:
number abs( mixed number )
but is has been changed to read
abs(int|float $num): int|float
That fits the definition of a BC break.

Any new feature which is added to the language, such as type hinting and strict typing, is supposed to be optional, not mandatory. Enforcing it whether you like it or not is plain WRONG!

Fine. You’re right. You are the god of PHP, handing down commandments. All Hail Your Decision. You never make poor code, and everything you create must always work forever. Your determination of what is right and wrong is absolute.

Or… PHP is an evolving language, that has decided to change how it handles this parameter in this function. I would point out that the RFC you hilighted as making the choice was reviewed by over 40 people who are responsible for making the decisions, and every single one of them voted yes.

You dont have to like what the language evolves into. Your options are to evolve with it, freeze yourself to an old version that conforms to your beliefs, or find another language.


The function documentation was changed. Yup. It happens.

So did removing mysql_ as a library. It still happened. The world didnt end; you changed your code to mysqli_ or PDO…

Keep going.

I am not the God of PHP, I am not handing down commandments, I am stating facts which are backed up by the documentation which I started reading in 2002.The behaviour of internal functions has been consistent with the documentation for over 20 years. This behavior is now being changed, and that is going to break virtually all existing applications which have relied on the traditional and documented behavior.

PHP has always been dynamically typed - it says so in the manual.

PHP has always been weakly typed - it says so in the manual in Type Juggling.

PHP has always coerced NULL into either an empty string or the the value zero depending on the context - it say so in the manual.

The expectation that code which I wrote 5, 10 or 15 years ago should carry on working in the latest release is not an unreasonable expectation. Backwards compatibility is a feature, not an option that can be discarded on a whim by dogmatic programmers who had no part in the creation of the language.

So the decision to break the language was made by just 40 people? What about the millions of developers who use the language to earn a living? Don’t their opinions count?

You clearly do not understand the difference between evolving and devolving. The language can only be improved by adding functionality, not by removing it

It was not a bug that PHP has operated in weak typing mode for over 20 years. This means that any expression or function ccould accept a value of any type and, using the rules explained in Type Juggling attempt to coerce it into the expected type.

While some changes have been necessary, such as replacing the old MySQL extension with a new one, changes such as those mentioned in this post are NOT necessary, they are simply the whims of a bunch of dogmatists who want to enforce their warped views of code “purity” on the entire world.

You kind of left off the second sentence in that paragraph:

So yes, it’s in the manual. So’s the second half.

Just because it’s the default doesnt mean everything uses it.
also, there’s the big red block underneath it that says

Again, go find anyone that coded the mysql_ functions into their code and see if they’re still doing it. Or ternaries with unqualified nesting. or anyone using ldap_sort(), or… or…or…
Not the first time. Not the last time. Sometimes things go away. It happens. It sucks, sure. But you change your code and you move forward.

1 Like

Possible, yes. Mandatory, no. It is an option which is OFF unless turned ON.

In this context the value must be a value of the type.

This text did not exist in the manual for version 7, it was changed for version 8. This change in the documentation matches the change in PHP’s behaviour. It is still a change, and a breaking change at that.

Just because it’s the default doesnt mean everything uses it.

It was used everywhere in the language up to and including version 7. It has changed in version 8. It is still a breaking change.

this behaviour is DEPRECATED as of PHP 8.1.0.

Just because a breaking change is documented does not make it a non-breaking change.

Again, go find anyone that coded the mysql_ functions into their code and see if they’re still doing it.

I don’t know how many people are still using the mysql_ functions, and neither do you. I changed to the mysqli_ functions when the new version of mysql was released. I am not averse to change when that change is for the better or has benefits. What I am against are breaking changes to established behaviour for NO GOOD REASON. I am not against type hinting or stricy typing provided that they are optional and not compulsory.

Just wanted to point out that deprecated does not mean it is an error. The code still works as before. Therefore, by definition, it is not a breaking change. You could capture the notices and that would be that.

You could contrast this with the time when count(null) was fixed to prevent null from being passed. That was an actual change which broke quite a bit of code though technically it was a bug fix.

Of course in PHP 9 the functions would no longer work. So you will need to eventually update your code. Or just stick with your current PHP version.


Even though with version 8.1 it will only issue deprecation notices and not fail, it WILL fail in version 9. Whether it’s now or later it is still a breaking change.

It is not a breaking change to fix a security issue or anything vitally important, it is just a virtue-signalling issue to satisfy the whims of a buch of dogmatic developers who think they rule the world. Millions of other application developers who use PHP would disagree.

I know exactly how many people are using the mysql_ functions in PHP 8. 0. Because they were removed in PHP 7.0.

Do I really need to go through the entire changelog of PHP and point out every time a function was removed from the language to you before you can grasp the concept that it is an evolution, not a devolvement. You dont like it. We get that. EVERYBODY gets that. You made that clear from word 1. The thing you relied on has been replaced by a different version. Like going from mysql_ to mysqli_. The language has changed.

Change your code.
Stay on an old version.
Find a new language.

Or keep shouting at clouds i guess. You do you. I’m done talking to a wall.

1 Like

I’m hoping that they add an option in php.ini to globally enforce strict typing rather than having to declare it in every script

At least you have the ability to exercise your choice by simply adding a single line of code to each script. Us poor schmucks who have large codebases which have run quite happily for years and wish to continue using the weak typing option now have to examine every script and fix EVERY call to a PHP function.

Have you tried a tool like PHPStan to help you with this? It’s not perfect, but it can save a lot of manual labour.


There is another tool called rector which can scan your code and suggest changes to support various PHP versions. In theory it can even make the changes. I have never been overly fond of the notion of letting some tool make automatic changes to my code but just having a list of suggested changes can be a big help.

1 Like

I have been lurking on this thread for some time and have concluded that the advice you are being given by @m_hutley and others have been spot on. You seem to be working off some premises that are not entirely sound and I thought I would clear up some misconceptions. Do know that I have over 25 years of experience as a programmer and have used PHP for nearly 18+ years in all sorts of environments including a codebase that is being used by a billion dollar tech company which utilizes PHP for some of it.

First of all, PHP has, for several years now, been moving the language away from its more problematic roots and is thus enhancing it. They are “evolving it”. Evolving can certainly mean taking away some features to increase the usability and enhance the language. m_hutley came up with the perfect example with the mysql_ functions. Couldn’t have been said better. Every language deprecates and removes features as it introduces and changes others. That is just a given in all languages (I should know, I regularly work in 12 of them).

Secondly, as general programming practice, you should NEVER be relying on a language to duck type your intentions as a regular rule. This leaves the interpreter to “guess” what you want to be done on its context and while this can be leveraged in spots, you are leaving yourself open to bugs. In short, in any programming language, you should know your types and be as explicit as possible. I am not saying duck typing is essentially bad, but if you are leaving user input or input from a database to determine what happens in an operation, you are playing with serious fire. It is half the reason other languages have chosen to be strongly typed to begin with.

Third, documentation. I find PHP documentation to actually be one of the best sources of documentation for any language I have ever used. They outline signatures, types, explore caveats, make notes of deprecation and upcoming breaking changes for a given version (usually in break out note boxes) and even return types. Python doesn’t even show return types in their documentation it is frustrating. Are they going to miss something every now and then? Sure, but usually it is corrected quickly. Just watch how often the documentation is updated (php docs are time stamped)

Fourth, languages change and those changes break things. Those of us around for PHP 4 to 5 saw many many breaking changes. Then we saw many more on PHP 5 to 7. There are more from PHP 7 to 8 and surely going to be more from PHP 8 to 9. The PHP working group communicates and discusses changes regularly and you can even contribute yourself. If you want to help redirect the conversation, get involved!

Lastly, as already mentioned, we know you are frustrated with having to make a lot of changes for features you think are just wacko or doesn’t fit with the spirit of the language. There are many tools mentioned that can certainly help. But know you don’t have to change these things overnight. PHP usually supports prior versions for a while and even some of the biggest platforms on the planet that use PHP (do keep in mind that PHP runs nearly a third of the net’s websites) usually sit back several versions. WordPress for instance recommends 7.4+. So you have time to make changes or change to another language. You will still find out that other languages introduce as many breaking changes regularly. Honestly, .NET is worse in my opinion. A framework developed by a company with their own goals and biases.

No need to come on a board like this and get yourself worked up. Sure it can suck when things change, but you have time, options and plenty of people here in this community that can assist you with great advice. Many of whom have been through multiple PHP version changes before.



If you are such a fan of strict typing then why did you choose to code in a language that didn’t have it? That sounds as sensible as visiting a Chinese restaurant and then complaining that they don’t serve pizza

You sound as if you only write programs that are use-once-then-throw-away. I doubt if you have ever written, or been involved in writing, a large application that has been maintained over several versions of PHP.

If you are a fan of strict typing then why did you choose PHP in the first place?

This thread has been threading the line for a while, but now that it’s gone full ad hominem I’ll just close it.

Thanks all for participating.