Use str_contains
over strpos
for tutorial example
#2716
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The first example on the PHP documentation that isn't a "hello world" is searching the
User-Agent
for the string"Firefox"
.This example currently uses
strpos
. I believe we should be usingstr_contains
.I believe this for a few reasons, but to start with I'll let the function descriptions do the talking:
vs.
str_contains
matches the semantics of what we are doing and eases the overhead of understanding what is happening.When using
strpos
we are also introducing the reader to:false
as a flag to indicate something" behaviourWhich is all additional overhead.
The current example also has double negatives that are hare to read left to right. The
str_contains
example feels much easier to comprehend, i.e.,versus
and...
vs
I understand that
str_contain
is a "newer" PHP function, however these are the documentation for the current PHP language - so we should take advantage and promote it's newer features, when it makes sense.The
str_contains
function is available in all currently supported PHP versions.Lastly, I removed the
<br />
from the example as it serves no purpose to introducing the reader to "control structures and functions". The next example handles mixing in HTML in the "Mixing both HTML and PHP modes". The later examples also don't reference the<br />
anyway, so kinda feels like unneeded noise we ca drop.