A #PHP global constant redefinition is a simple warning.
A #PHP class constant redefinition is a full Fatal Error.
I am so used to the Fatal error, that I expected the global constant to behave the same. Shouldn't they?
[#]phptip #phptrick
https://php-tips.readthedocs.io/en/latest/tips/constant_redefinition.html
=> More informations about this toot | More toots from dseguy@phpc.social
@dseguy That deserves a RFC
=> More informations about this toot | More toots from galvao@phpc.social
@galvao Indeed, you're right.
I would start with a legacy check: in particular, multiple inclusion of the same would be now a Fatal error.
And with autoload, it might be a tiny fraction of codes.
=> More informations about this toot | More toots from dseguy@phpc.social
@dseguy Do you have karma to do it?
=> More informations about this toot | More toots from galvao@phpc.social
@galvao I can check (a lot) of code, and write the RFC. Most of the value would be here.
Then, find someone else to do it :) .
=> More informations about this toot | More toots from dseguy@phpc.social
@dseguy Fanatical dedication to backwards compatibility, innit? I susect there was concern over breaking WP or something.
=> More informations about this toot | More toots from pollita@phpc.social
@pollita It would leave a lot of WP installations unusable. And hinder further upgrades...
Because blaming the shitty BC policy of the PHP-team is much easier than fixing shitty code and check whether a constant is already defined before redefining it...
/cc @dseguy
=> More informations about this toot | More toots from heiglandreas@phpc.social
@heiglandreas @pollita @dseguy I’m not sure I’ve seen this particular code in wide spread use in WP. I could be wrong but it’s not a typical pattern in WP plugins or core.
=> More informations about this toot | More toots from skc@scottodon.com
@skc Checking whether a constant is already defined before defining it?
/cc @pollita @dseguy
=> More informations about this toot | More toots from heiglandreas@phpc.social
@heiglandreas @pollita @dseguy yeah that’s the normal practice I’ve seen, checking to see if it’s defined before defining it
=> More informations about this toot | More toots from skc@scottodon.com
@skc I've seen enough logfiles that showed, that it is not handled like that everywhere 😁
/cc @pollita @dseguy
=> More informations about this toot | More toots from heiglandreas@phpc.social
@heiglandreas @skc @pollita I measure (very roughly) about 1 out of 3 project defining global constants. And even more checking their existence.
It might be worth checking a number of those usages, to see actual usage, it might be interesting.
=> More informations about this toot | More toots from dseguy@phpc.social
@heiglandreas @pollita @dseguy to be fair: WP core and most of plugins will not break for this. But WP has a configuration-by-constants approach, and people in their wp-config do whatever. So, yes, many WP installations might break, but not something that can be fixed in WP code.
=> More informations about this toot | More toots from gmazzap@phpc.social
@gmazzap
if (! defined('ABC')) {
define('ABC', xyz);
//possibly even
ABC=xyz;
}
Looks not too complicated... 🤔
/cc @pollita @dseguy
=> More informations about this toot | More toots from heiglandreas@phpc.social
@gmazzap @heiglandreas @dseguy
Constants that aren't constant...
Ya know, PHP has a cool feature for that. They're called variables. Cause they vary.
=> More informations about this toot | More toots from pollita@phpc.social
@heiglandreas @pollita @dseguy I've never figured out who these admins are that upgrade #PHP on the server but not #WordPress on the site. 🤔
=> More informations about this toot | More toots from syntaxseed@phpc.social
@syntaxseed Those that maintain shared hosting where users can install whatever they want?
And users then decide to not use the providers supplied oneclick installer... And also never update WP because "It'll break 😱"
I've seen things.... 🙈
/cc @pollita @dseguy
=> More informations about this toot | More toots from heiglandreas@phpc.social
@heiglandreas @pollita @dseguy I use a lot of shared hosting. Never had the PHP version change from under me- typically I go to my control panel & can choose from versions currently available. I then have to flip the "switch" in order to upgrade PHP.
I feel like people who don't bother with WP upgrades aren't going to do either.
If the version changes from under you, either the host is awful or you ignored years of warnings (we've been getting 5.x discontinuation notices for many years. 🤣
=> More informations about this toot | More toots from syntaxseed@phpc.social
@heiglandreas @pollita @dseguy But yeah... I'm sure the horror stories are everywhere!
I'm just not sure that "we" (PHP) should be shielding them. 😉
=> More informations about this toot | More toots from syntaxseed@phpc.social
@syntaxseed I hope you didn't get me wrong: We shouldn't!
/cc @pollita @dseguy
=> More informations about this toot | More toots from heiglandreas@phpc.social
@heiglandreas @pollita @dseguy Nope, I was agreeing with you. 😊
=> More informations about this toot | More toots from syntaxseed@phpc.social
@heiglandreas @pollita @dseguy We should, IMO, take advantage that we're already talking about PHP9 and make a RFC for it =)
=> More informations about this toot | More toots from galvao@phpc.social
@pollita Yes, I suspect backward compatibility.
Now, I'd like to run some SCA check to spot such problems, and see how it can be fixed (automatically? manually?).
That way, it might help everyone.
=> More informations about this toot | More toots from dseguy@phpc.social
@pollita @dseguy it used to be a notice in PHP 7 and was elevated to a warning in 8.
I'm sure we will just have another round of elevating warnings to errors in PHP 9.
=> More informations about this toot | More toots from Girgias@phpc.social
@dseguy I suspect it can be problematic if packages define global constance. (I don't know if there are packages who are doing that)
=> More informations about this toot | More toots from tvbeek@phpc.social
@tvbeek A quick search across 3100+ OSS source codes shows 902 (29%) of them using define(): even more of them use const, although for class constant too.
Then, 1370 uses defined() (44%): again, class and global, so actual might be lower.
So, that is roughly one out of 3 of us.
If it is not you, or me, who can it be? names! names! 😂
=> More informations about this toot | More toots from dseguy@phpc.social This content has been proxied by September (ba2dc).Proxy Information
text/gemini