Re: Why PHP sucks - farce or is there a bit of truth?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 13-10-18 04:06 AM, Tim-Hinnerk Heuer wrote:
Clearly you haven't read the whole thread. The subject line asks the
question:
>
  "Why PHP sucks - farce or is there a bit of truth?" - and there is a
  link to the article of which I found many more btw.

Actually, I did, but thanks for the huge font... I needed to step out of the office to take it all in and so I grabbed a coffee too.

I am not dissing PHP at all. In fact, as I said, I have been a PHP
programmer for many years...

I didn't say you were.

It was just one thing that puzzled me and that I followed up on. I even
asked: "Is it faster to execute/implement if evaluated left-to-right?"
which would be an argument for this.

You're on the wrong list to ask this question... that's something more appropriate for Internals where they discuss the PHP engine development itself.

I've heard many people moan about lots of languages and there are
weaknesses in most if not all of them.

Indeed.

All I'm trying to do here is improving the language by raising issues
(one at a time) on this list to better understand the language and get
people thinking.

You're on the wrong list... internals is where you improve the language, and the best way to do so is to write an RFC, submit it for review, and depending on feedback you can write the code.

Another issue I found is:
Not so useful return values:

<?php
$b = false;
$c = "orange";
$a = $b || $c;
echo $a;

outputs:
1

No, you'll find that $a contains the boolean value true. It just happens to print as a 1. In this case it makes perfect sense... you are using a boolean logic operator, it should return a boolean. Yes, yes, I know some languages return the result of the first expression itself that evaluates to true.
<?php

    $b = false;
    $c = 'orange';
    $a = $b || $c;
    var_dump( $a );

?>

JS seems more convenient here. As a scripting language it also has the
notion of truthy but returns the default value "orange".

Explain that notion of "default". Why is orange the default. What if the order of evaluation were to be changed due to some optimization in the future. Then the "default" would change. If you WANT the value then you should make it explicit instead of obfuscating your code by relying on the underlying implementation:
<?php

    $b = false;
    $c = 'orange';
    ($a = $b) || ($a = $c);
    var_dump( $a );

?>


:-)

;)

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux