Re: [PHP4BETA] broken or probably not implement!
| From: | Faisal Nasim | Date: | Fri, 18 Feb 2000 12:12:36 +0000 |
| Subject: | Re: [PHP4BETA] broken or probably not implement! | ||
| References: | 1 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-10444@lists.php.net to get a copy of this message | ||
: I'm not sure what you're saying here, all of the results reported by PHP
: are correct. 10||1 is true (boolean). The fact that Perl reports 10 is
Then why:
$str = 10 or 1 // = 10
and
$str = 0 or 1 // = 0
0 is false, and 'or' has low precedence, so result should be 1!
Also:
$str = 0 || 1 // = 0
$str = "" or "faisal"; // ""
In Perl, it will behave as a conditional operator and won't return
the boolean match:
$str = "" || "faisal"; // faisal
$str = "" or "faisal"; // ""
BITWISE:
print "" | "faisal"; // ""
print 10 | 100; // 110
All I was trying to simplify this:
$str = (int) $blah;
if ( ! $str ) $str = 0;
Perl: $str = int $blah || 0;
PHP: $str = (int) $blah ? $blah : 0;
OR:
$total = somelongfunction ( $arg );
if ( ! $total ) $total = 100;
Because this will be silly to call our *long* function twice like this:
$total = somelongfunction ( $arg ) ? somelongfunction ( $arg ) : 100;
Where, in Perl I can:
$total = &somelongfunction || 100; # not returning boolean value!
: meaningless, any value that translates into true is valid. If you want to
: conduct bitwise operations, you should be using the bitwise operators,
: i.e. 10|1.
:
:
: Zeev
:
: On Fri, 18 Feb 2000, Faisal Nasim wrote:
:
: > Greetings,
: >
: > PHP could use some more flexibility and some bug fixing!
: >
: > $str = 10 || 1; // 1
: > $str = 0 || 1; // 1 ... correct
: > $str = 10 or 1; // 10 ... correct
: > $str = 0 or 1; // 0
: >
: >
: > Either PHP doesn't support them well now, or its completely
: > broken! Any info?
: >
: > Perl reports:
: >
: > 10 ... correct
: > 1 ... correct
: > 10 ... correct
: > 0 ... correct, according to the precedence table, I reckon.
: >
: > Thank you!
: