Mahngiel Posted August 21, 2012 Share Posted August 21, 2012 I want a speedy ternary operator! I don't know if any other langs have this, but it would be super cool $this->object->property['value'] ? $this->object->property['value'] : 'you suck'; becomes $this->object->property['value'] ? &$$ : 'you suck'; the &$$ (or any other way to reference the preceding value) simply becomes a reference to the value being conditionalized. For instances where two PHP variables are being compared, the first var is the one who gets perpetuated over. $somevar === $othervar ? &$$ : 'no match' equates to $somevar === $othervar ? $somevar : 'no match' Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/4/#findComment-1371116 Share on other sites More sharing options...
trq Posted August 21, 2012 Share Posted August 21, 2012 Already exists. Since PHP 5.3, it is possible to leave out the middle part of the ternary operator. Expression expr1 ?: expr3 returns expr1 if expr1 evaluates to TRUE, and expr3 otherwise. Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/4/#findComment-1371120 Share on other sites More sharing options...
Mahngiel Posted August 21, 2012 Share Posted August 21, 2012 well i'll be damned! i guess the fact of it being called 'middle part' on the php manual eluded any sort of google results. Cheers, thorpe! Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/4/#findComment-1371132 Share on other sites More sharing options...
scootstah Posted August 21, 2012 Share Posted August 21, 2012 It's kind of not-that-useful, though. For example: $a = 'a'; var_dump(isset($a) ?: false); = (bool)true, not "a" It's really only useful if you can do something like: $a = 'a'; var_dump($a ?: false);.But, then you have to make sure the variable is initialized first. So yeah, it exists, but it's not terrible useful. EDIT: If you want to assign a variable, you can do something like: <?php $foo = 'bar'; isset($foo) AND $bar = $foo; But, unfortunately you can't echo that way. Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/4/#findComment-1371157 Share on other sites More sharing options...
kicken Posted August 22, 2012 Share Posted August 22, 2012 Yea, I was kind of excited when I first read about being able to do that, but the I realized it wasn't really useful because you need the isset/empty checks to prevent the e_notice errors. It'd be nice if they made a special case or something for those so that it would work. $action = isset($_GET['action'])?:'default'; would be nice if it worked. Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/4/#findComment-1371383 Share on other sites More sharing options...
Adam Posted August 22, 2012 Share Posted August 22, 2012 Or perhaps even better would be an additional isset-esque function: $bar = issetdefault($foo->bar, false); Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/4/#findComment-1371391 Share on other sites More sharing options...
Andy-H Posted August 24, 2012 Share Posted August 24, 2012 Or perhaps even better would be an additional isset-esque function: $bar = issetdefault($foo->bar, false); function isset_or($isset, $or) { return isset($isset) ? $isset : $or; } Save to lib/php, simples =P Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/4/#findComment-1372064 Share on other sites More sharing options...
Adam Posted August 24, 2012 Share Posted August 24, 2012 That will trigger a notice when the variable isnt set. Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/4/#findComment-1372066 Share on other sites More sharing options...
Hall of Famer Posted August 30, 2012 Author Share Posted August 30, 2012 Well C++'s Friend class concept is cool too, PHP may consider borrow it for next version? I know they've been adding OOP supports primarily based on Java since version 5, but Java is not the only OO programming language after all. Didnt they just get Trait? I believe this was not an idea originated from Java. Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/4/#findComment-1373804 Share on other sites More sharing options...
scootstah Posted August 30, 2012 Share Posted August 30, 2012 I believe this was not an idea originated from Java. Neither was the majority of PHP's OOP implementation. OOP existed long before Java did. Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/4/#findComment-1373888 Share on other sites More sharing options...
Hall of Famer Posted August 31, 2012 Author Share Posted August 31, 2012 I believe this was not an idea originated from Java. Neither was the majority of PHP's OOP implementation. OOP existed long before Java did. Of course I know about this, but Java did introduce some nice OOP syntax and concept that makes it more convenient and useful to program in OOP. If OOP exists for the mere purpose of information hiding, then perhaps we dont really need it at all as you can do the same job with functions. Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/4/#findComment-1374152 Share on other sites More sharing options...
.josh Posted August 31, 2012 Share Posted August 31, 2012 Of course I know about this, but Java did introduce some nice OOP syntax and concept that makes it more convenient and useful to program in OOP. If OOP exists for the mere purpose of information hiding, then perhaps we dont really need it at all as you can do the same job with functions. But...I thought that IS the main purpose of OOP. The major selling point of OOP is being able to reliably abstract code. The point is that people can then add to or remove from it, without worrying about breaking something somewhere else. I would not consider this to be "mere", nor can procedural programming accomplish this in the way OOP can. But the major argument here is whether or not OOP is superior to procedural, and whether or not procedural even has any place in the programming world. And the answer to that is....stop comparing your hammer to your screwedriver. There differences in syntax, but that is not the driving difference. The driving difference is that they are different styles,'ways' of programming. Programming a CMS with the intent of being able to allow random 3rd parties to easily specify which features to add or remove, and easily develop modules/addons/whatever for it...sure, you can do that procedurally, but your life will be much easier if you did it OOP style. Programming a site for a mom and pop business who wants little more than a glorified electronic business card. Sure, you can go OOP style and spend 10 hours deving it...or you can go procedural and spend 2 hours deving it. Which do you think makes more sense, knowing mom and pop have no interest in significantly altering or expanding their site? Knowing that they will more easily swallow a 2 hour bill vs 10 hour bill? Right tool for the right job. Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/4/#findComment-1374244 Share on other sites More sharing options...
scootstah Posted August 31, 2012 Share Posted August 31, 2012 but Java did introduce some nice OOP syntax and concept that makes it more convenient and useful to program in OOP. Such as ... ? Or are you just talking out of your ass again? Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/4/#findComment-1374275 Share on other sites More sharing options...
The Little Guy Posted September 2, 2012 Share Posted September 2, 2012 I want object literals and more similarities to JS! Example: <?php $something = "a fancy string"; (function($values){ $obj = { var1: "a string", var2: [ "one", "two", "three" ], aFunc: function(){ return 12345; } }; echo $obj->var1; return $obj->aFunc(); })($something); Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/4/#findComment-1374706 Share on other sites More sharing options...
trq Posted September 3, 2012 Share Posted September 3, 2012 I want object literals and more similarities to JS! There is an RFC in draft that covers this. See https://wiki.php.net/rfc/objectarrayliterals On a side note, generators just got voted in to 5.5. https://wiki.php.net/rfc/generators . Yay! Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/4/#findComment-1374758 Share on other sites More sharing options...
kicken Posted September 3, 2012 Share Posted September 3, 2012 I was looking through the RFC's the other day and spotted the loop+else one. I'm a fan of that one and would like to see it get implemented. I'd like to see it extended a bit too. as it is, it would allow something like: while ($row=$db->fetch()){ echo '...row data...'; } else { echo 'No rows found.'; } The extension I think should go along with it would allow something like: while ($row=$db->fetch()){ echo '...row data...'; } finally { echo '...summary info...'; } else { echo 'No rows found.'; } I'm not sure I'm necessarily happy with the names else and finally as the keywords (can be confusing, multiple ways to interpret it) but I've not thought up anything better. Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/4/#findComment-1374771 Share on other sites More sharing options...
KevinM1 Posted September 3, 2012 Share Posted September 3, 2012 Have Ruby/C# style object properties gotten the go-ahead yet? There was a rather nice proposal months ago, but it wasn't voted on the last I checked. Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/4/#findComment-1374778 Share on other sites More sharing options...
trq Posted September 3, 2012 Share Posted September 3, 2012 Assuming this is what you mean't, it's still under discussion I think. https://wiki.php.net/rfc/propertygetsetsyntax-as-implemented Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/4/#findComment-1374780 Share on other sites More sharing options...
ignace Posted September 3, 2012 Share Posted September 3, 2012 If they do that they may aswell add support for: class Foo { private $bar = new Bar; } Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/4/#findComment-1374792 Share on other sites More sharing options...
KevinM1 Posted September 3, 2012 Share Posted September 3, 2012 Something they should seriously consider adding: a parse error if 'global' is used within class code, and a warning if it's used anywhere else. It's the latter half of 2012, yet I still see 'global' used frequently both here and on Stack Overflow. Ridiculous. Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/4/#findComment-1374934 Share on other sites More sharing options...
Christian F. Posted September 3, 2012 Share Posted September 3, 2012 Something they should seriously consider adding: a parse error if 'global' is used within class code, and a warning if it's used anywhere else. It's the latter half of 2012, yet I still see 'global' used frequently both here and on Stack Overflow. Ridiculous. Quoted for Truth! Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/4/#findComment-1374945 Share on other sites More sharing options...
Mahngiel Posted September 4, 2012 Share Posted September 4, 2012 Something they should seriously consider adding: a parse error if 'global' is used within class code, and a warning if it's used anywhere else. It's the latter half of 2012, yet I still see 'global' used frequently both here and on Stack Overflow. Ridiculous. While i don't disagree with you at all, i fear half of the web would explode! Look at the fallout from GoDaddy's hosting services' recent changes. If there are websites out there relying on software source last updated 10 years ago, how can ye hath faith phasing global out would accomplish much at all. Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/4/#findComment-1374988 Share on other sites More sharing options...
scootstah Posted September 4, 2012 Share Posted September 4, 2012 Something they should seriously consider adding: a parse error if 'global' is used within class code, and a warning if it's used anywhere else. It's the latter half of 2012, yet I still see 'global' used frequently both here and on Stack Overflow. Ridiculous. While i don't disagree with you at all, i fear half of the web would explode! Look at the fallout from GoDaddy's hosting services' recent changes. If there are websites out there relying on software source last updated 10 years ago, how can ye hath faith phasing global out would accomplish much at all. Most websites using older versions of PHP will still function properly under PHP 5.3. muffled laughter Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/4/#findComment-1374993 Share on other sites More sharing options...
Monkuar Posted September 4, 2012 Share Posted September 4, 2012 i honestly cannot think of anything new to be added as I've barely touched the waters with php and i've been doing it for years, im a slow learner, but i am going it at it. most of my errors and decline of my coding is im not reading the full documentation or the parameters for each function, that always ends up me making topics on phpfreaks trying to re-invent the wheel of something, when im just missing a parameter for the function.... lmfao i do like that while else though, i've always wanted to do that. and im not going to lie, hall of famer has been pretty damn humble through this topic Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/4/#findComment-1374994 Share on other sites More sharing options...
squigs Posted September 4, 2012 Share Posted September 4, 2012 And I'm still trying to pass grade eight Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/4/#findComment-1375029 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.