Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,208,367 members, 8,002,373 topics. Date: Thursday, 14 November 2024 at 09:55 AM |
Nairaland Forum / Science/Technology / Programming / Php7: Null Coalescing Operator (1378 Views)
Any Nigerian Hosting With Php7 / I Want To Be A Coding Operator / My Personal Performance Test On PHP7 VS Facebook HHVM & New Features (2) (3) (4)
Php7: Null Coalescing Operator by guru01(m): 9:59am On Jun 22, 2016 |
The Null Coalescing Operator makes life easier for php programmers. Thanks to the php core team members and every other contributors. Null Coalescing Operator helps you check for null value. Previous version of php here is how it is done: $firstname = isset($user->firstname) ? $user->firstname : 'guest'; But now cleaner and easy with PHP7: $firstname = $user->firstname ?? 'guest'; Enjoy coding, and stay safe. |
Re: Php7: Null Coalescing Operator by Nobody: 10:47am On Jun 22, 2016 |
*Spreads mat* them call me PHP Maestro, but me i no sabi all this one walahi. So I hereby 'commoth' my php championship belt (or be-li-ti) and e-hand it over to the indian guru, and i doff my hat as well. Hailing: Baba O! |
Re: Php7: Null Coalescing Operator by teampregar(m): 11:20am On Jun 22, 2016 |
So in php 7 there is no value to assign the variable to if the condition is false?? I like the former operator better. |
Re: Php7: Null Coalescing Operator by Nobody: 12:01pm On Jun 22, 2016 |
^^^You will, better start changing your concepts before the world overtakes you here is my take on PHP 7, since the servers are all still using 5.3, 5.4, there is no point in using something that can only run on my localhost. Even the latest version of Joomla and Co are still using php 5.x (usually not higher than 5.4), I ain't gonna be make a mistake i made sometime back. I remember when PHP 5.0 first came out, I was one of the first few people to migrate. I did a fantastic app then, when i upload the stuff like this, na so wahala start only for me to find out the web hosts were still using 4.x, i migrate host na the same the same. Them tell me to buy vps or dedicated server and customize. Na so i jejely downgrade the app back to 4.x. |
Re: Php7: Null Coalescing Operator by teampregar(m): 12:06pm On Jun 22, 2016 |
dhtml18:How much does a vps cost in naija and do i need to manage it by myself? |
Re: Php7: Null Coalescing Operator by guru01(m): 1:16pm On Jun 22, 2016 |
dhtml18:You may be write, it depends on the host. The host I use are already supporting php7 as we speak and its on a shared server. |
Re: Php7: Null Coalescing Operator by guru01(m): 1:18pm On Jun 22, 2016 |
teampregar:If you check the code I wrote, you can see that the guest is assign to the var if false. |
Re: Php7: Null Coalescing Operator by guru01(m): 1:21pm On Jun 22, 2016 |
teampregar:You don't need a vps to run php7 code. Just ask the host if they support it, if not look for other host that does. |
Re: Php7: Null Coalescing Operator by jidez007: 1:34pm On Jun 22, 2016 |
There are some vps that are as cheap as shared hosts. An example is http://ovh.us which is cheaper than Godaddy shared host. I can't remember the last time I saw cpanel sef and most of my websites are using hhvm |
Re: Php7: Null Coalescing Operator by jidez007: 1:36pm On Jun 22, 2016 |
In Laravel blade you can just do {{ $user->firstname or 'guest' }} and it translates to the above |
Re: Php7: Null Coalescing Operator by Nobody: 2:08pm On Jun 22, 2016 |
^^^many frameworks have this functionality already (even my own smallboy framework). |
Re: Php7: Null Coalescing Operator by Nmeri17: 9:41pm On Jun 22, 2016 |
Inasmuch as I would like to learn something new, what would it profit me to sacrifice readability over elegance? Besides, the operator borders on redundance; because, most times you need to use the ternary operator, you're evaluating the truthy of another statement and not necessarily the assigned value as is used in the OP's example. |
Re: Php7: Null Coalescing Operator by jidez007: 10:15pm On Jun 22, 2016 |
^^^ probably in your template when you need to echo something <?= $user->firstname ?? 'guest' ?> |
Re: Php7: Null Coalescing Operator by jidez007: 10:20pm On Jun 22, 2016 |
Php7 is 2x faster than php5.6 but not still as fast as hhvm. What I would be more interested in is Php7 Vs hhvm, will people using hhvm start migrating back to php because of the improved speed? |
Re: Php7: Null Coalescing Operator by guru01(m): 11:28pm On Jun 22, 2016 |
jidez007:Hhvm is a form of mechanism for compiling php codes. Php7 is a programming language, and is as fast as hhvm. Check online for benchmarks. |
Re: Php7: Null Coalescing Operator by jidez007: 6:25pm On Jun 25, 2016 |
You are right, php 7 has really caught up and it performs better on servers with lower resources. And this: http://www.zend.com/website/var/tmp/image-thumbnails/10000/14913/thumb__auto_8f003aa3d171b0e739a4314b85eb4f3d/php7-infographic.png Shows php7 has the fastest dynamically typed language |
(1) (Reply)
Building A Kivy Andriod App. I Need Guidance / How To Learn Any Programming Language Quickly (part 2) / Instagram Integration
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 29 |