Jump to content

Recommended Posts

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'

  • Replies 123
  • Created
  • Last Reply

Top Posters In This Topic

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.

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.

 

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.

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.

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.

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);

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.

 

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.

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!

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.  :confused:

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.  :confused:

 

Most websites using older versions of PHP will still function properly under PHP 5.3.

 

muffled laughter

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  :shy:

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.