Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
PHP
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==== Syntax changes and additions ==== PHP 8 includes changes to allow alternate, more concise, or more consistent syntaxes in a number of scenarios. For example, the nullsafe operator is similar to the [[null coalescing operator]] {{code|??}}, but used when calling methods.<ref name="wiki.php.net" /> The following code snippet will not throw an error if {{code|getBirthday()}} returns null: <syntaxhighlight lang="php"> $human_readable_date = $user->getBirthday()?->diffForHumans(); </syntaxhighlight> Constructor property promotion has been added as "[[syntactic sugar]]," allowing class properties to be set automatically when parameters are passed into a class [[Constructor (object-oriented programming)|constructor]].<ref name="Brent" /> This reduces the amount of [[boilerplate code]] that must be written.<ref>{{cite web |last1=Roose |first1=Brent |title=PHP 8: Constructor property promotion |url=https://stitcher.io/blog/constructor-promotion-in-php-8 |access-date=30 April 2024}}</ref> Other minor changes include support for use of {{code|::class}} on objects, which serves as an alternative for the use of {{code|get_class()}};<ref name="Brent" /> non-capturing catches in try-catch blocks; variable syntax tweaks to resolve inconsistencies; support for named arguments; and support for trailing commas in parameter lists, which adds consistency with support for trailing commas in other contexts, such as in arrays.<ref name="PHP" />
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
PHP
(section)
Add topic