#46148 [Com]: ((strlen($someString) = $someInteger) ? someStatement : someStatement) fails

2008-09-22 Thread tf at oopsilon dot com
 ID:   46148
 Comment by:   tf at oopsilon dot com
 Reported By:  Yuji1 at mail dot com
 Status:   Open
 Bug Type: Scripting Engine problem
 Operating System: Windows XP Pro SP2
 PHP Version:  5.2.6
 New Comment:

Firstly, your ternary's the wrong way up. You're asking whether a
string is less than 300 chars long, and if it is getting the first 300
chars.

Secondly, the ternary has a higher precedence than comparison: ($foo 
300 ? 1 : 2), for example, is ($foo  (300?1:2)).

Your statement should probably be:
(strlen($foo)=300)?$foo:substr($foo,0,300)


Previous Comments:


[2008-09-22 02:40:33] Yuji1 at mail dot com

Description:

(somefunction($someObject) someOperator $someObject) ? someStatement :
someStatement

and

((somefunction($someObject) someOperator $someObject) ? someStatement :
someStatement)

fail

but

((somefunction($someObject someOperator $someObject) ? someStatement :
someStatement)

works. :/

Reproduce code:
---
$queryResults was an array of strings, [1] being a string. It had
length, yes.

I used:
$queryResults[1] = (strlen($queryResults[1]) = 300) ?
substr($queryResults[1], 0, 300) : $queryResults[1]);

It however fails.

This fails too:

$queryResults[1] = strlen($queryResults[1]) = 300 ?
substr($queryResults[1], 0, 300) : $queryResults[1];

This works:

$queryResults[1] = (strlen($queryResults[1] = 300) ?
substr($queryResults[1], 0, 300) : $queryResults[1]);

Expected result:

I expected it to well, shorten the length to 300.

Actual result:
--
Completely fails. In fact, without the (strlen($queryResults[1] = 300)
being that way, it does this (example is of a database query, and PER
ROW IT PRINTS OUT THE FOLLOWING STRING, THE POST STRING FOR NEWS):

First post:
StringStringStringString

Second post:
StringStringStringStringStringStringString

Third post:
StringStringStringStringStringStringStringStringStringString

Etc.





-- 
Edit this bug report at http://bugs.php.net/?id=46148edit=1



Bug #17288: ord returns wrong ascii values

2002-05-17 Thread tf

From: [EMAIL PROTECTED]
Operating system: linux
PHP version:  4.1.2
PHP Bug Type: *General Issues
Bug description:  ord returns wrong ascii values

ascii values for \b... \a (and some more) are missing.
they returns only 92.

e.g. value for \b should be 8...
-- 
Edit bug report at http://bugs.php.net/?id=17288edit=1
-- 
Fixed in CVS:http://bugs.php.net/fix.php?id=17288r=fixedcvs
Fixed in release:http://bugs.php.net/fix.php?id=17288r=alreadyfixed
Need backtrace:  http://bugs.php.net/fix.php?id=17288r=needtrace
Try newer version:   http://bugs.php.net/fix.php?id=17288r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=17288r=support
Expected behavior:   http://bugs.php.net/fix.php?id=17288r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=17288r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=17288r=submittedtwice
register_globals:http://bugs.php.net/fix.php?id=17288r=globals