Needs work
Project:
Drupal core
Version:
main
Component:
base system
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
17 Mar 2020 at 15:57 UTC
Updated:
24 Jan 2023 at 15:29 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
cilefen commentedComment #3
init90+1 to
is_null, for me it more readable variantComment #4
jungleUsed phpbench, https://phpbench.readthedocs.io/en/latest/index.html
Command used:
Reports and the CheckNullBenchmark.php file attached.
Tested against PHP 7.3.9 and 7.4.2. is_null seems slightly better. Or no noticeable difference.
personally, I prefer === NULL, as I prefer === than == when they two are interchangable under a context.
Would vote for won't fix.
Comment #5
jungleComment #6
jungleOr rescope this to replacing
is_null($variable)to\is_null($variable)?See a link @alexpott shared on slack to @catch https://twitter.com/Stof70/status/1251236840876761089 or Null checks are a performance bottleneck of this library #96
Comment #7
jungleNo obvious difference from the benchmark, among
===NULL,is_null()and\is_null()Theoretically, under the namespaced context,
\is_null()is better thanis_null()probably,is_null(), looking up functionis_null()at the current namespace first, not found, continue and found\is_null(), and executing,\is_null(), no extra lookupComment #8
andypostI bet it expected behaviour of PHP since namespaces started to work - lookup in namespace first and then in global scope
Interesting to check performance impact of prefixing all "global" functions... Better to explore it in separate issue
Comment #9
alexpottThis is likely to only have an impact in functions that are called many many times - I don’t think a blanket replace is in order here - but many we could identify any low level global function calls where this is significant.
Comment #10
dqd#7 - Look at this and this video (time set to the important point) demonstrating (in another case) how
is_arrayvs\is_array()oris_null()vs.\is_null()can be a huge difference in performance.Comment #11
init90Here is a discussion about implementing a fully qualified function in Typo 3: Should we use fully qualified function (FQN) calls like \is_array in the core?
Comment #12
cilefen commented@init90 I feel like there is such an issue for Drupal but I couldn't find it in a quick search.
Comment #13
catchFrom one of those links:
This might be a nicer way to do it than
\is_array()everywhere.Comment #20
smustgrave commentedThink it would be nice to maybe have a phpcs check? Should this be a policy idea maybe?