Bug #46408 [Com]: Locale number format settings can cause pg_query_params to break with numerics

2012-04-18 Thread claude dot pache at gmail dot com
Edit report at https://bugs.php.net/bug.php?id=46408&edit=1

 ID: 46408
 Comment by: claude dot pache at gmail dot com
 Reported by:alec at smecher dot bc dot ca
 Summary:Locale number format settings can cause
 pg_query_params to break with numerics
 Status: Wont fix
 Type:   Bug
 Package:PostgreSQL related
 Operating System:   *
 PHP Version:5.*, 6
 Assigned To:yohgaki
 Block user comment: N
 Private report: N

 New Comment:

@yohgaki (and others)

I think that, the root of the problem is the way PHP uses
the locale information, which I consider deeply broken.
Here are the  details:

In my understanding, the locale information is useful only
for *output*, i.e. for messages destined to the user.
They should not be used for any internal conversion
from one type to the other, unless the result is
destined to output.

The problem is, that PHP uses the locale for any
automatic conversion from number to string.
This behaviour is ok in the following case:

echo "Three and a half is: " . $number;

However, in the following cases, this is NOT correct,
because the resulting string must not be localised:

* constructing a JSON object (I hope that json_encode()
  does NOT use internal number-to-string conversion);
* using bcmath package (I have personnaly be bitten by
  this misfeature);
* construct a SQL request (the present case);
* etc.

In all these cases, you have to do one of the following options:
(1) never use any locale other than en_US
   (and re-implement manually the locale feature);
(2) carefully check the type of each and every parameter
and explicitely perform a correct conversion when needed,
e.g. using number_format(..., '.', '');
(3) fix PHP to NOT use locale for number-to-string conversion
unless it is explicitely asked for
   (side note: historically, there has been a similar
   problem with the "magic quote" misfeature);
(4) modify the modules bcmath, postgresql, etc,
   so that they circumvent the mentionned PHP misfeature,
   i.e., they do the  option (2) above at your place.

In my dreams, the option (3) would be implemented,
but pragmatically, I think that option (4)
has more chance to be implemented rapidly, if ever.

I think that alec asked precisely the option (4) to be implemented.
(Personnally, I have opted for option (1).)

Claude

P.S. The option (4) might seem a non-optimal hack.
However, do not forget that programming languages
and API should be adapted to the needs of the programmers,
and not the other way round.


Previous Comments:

[2012-04-18 03:13:12] yohg...@php.net

You misunderstand how libpq/PostgreSQL works.

If you think you can make proper patch for this, clone git source and send pull 
request.
No one will stop you from that.


[2012-04-18 02:58:26] alec at smecher dot bc dot ca

I believe pg_query_params is broken until this is resolved, but it looks like 
we're not going to agree on it. I hope someone else can speak up if they do 
think this is a bug.

Since we disagree on the approach any patch I write to correct it will be 
rejected.

I'll add a comment to the manual page for pg_query_params to document this.


[2012-04-18 02:26:48] yohg...@php.net

BTW, you are reading PostgreSQL manual wrong.

libpq's functions never care about data types, but the server is.

If you are curious still, try to make patch that meets the requirement I've 
wrote.


[2012-04-18 02:19:38] yohg...@php.net

IIRC, MDB2 cares data types. (which I think it's a design problem for loosely 
type langs.) Therefore, it may change behavior according to locale.

Anyway, It's not a matter of argument. It's the way it works. As I explained 
repeatedly, ALL params are passed as string and types are NEVER cared in C API. 
To know the data type, module should issue an additional query to get meta 
data. 
Additional query for each query is severe performance hit.

Therefore, it is a PHP programmer's responsibility (or Perhaps, PostgreSQL. If 
they would like to change behavior via client environment vars. I guess they 
would not.)

If you could submit patch that works for all data types and does not require 
additional query, I'll review it.


[2012-04-18 01:30:38] alec at smecher dot bc dot ca

Your example of storing a string-formatted double in a varchar column strikes 
me as an unusual case involving a type mismatch, and can be worked around 
clearly an

#51016 [NEW]: Always associate "else:" followed by colon to an "if:" followed by colon

2010-02-11 Thread claude dot pache at gmail dot com
From: claude dot pache at gmail dot com
Operating system: irrelevant
PHP version:  5.3.1
PHP Bug Type: Feature/Change Request
Bug description:  Always associate "else:" followed by colon to an "if:" 
followed by colon

Description:

In case of ambiguity, the statements "else" and "elseif" are always 
associated to the last previous "if" or "elseif". This rule is not 
convenable when the else/elseif is followed by a colon and the last 
previous if/elseif is not.

See also: http://bugs.php.net/bug.php?id=838

Reproduce code:
---
if(foo):
// some code here
if (bar) baz;
else:
// some code here
endif;

Expected result:

Since the "else" is followed by a colon (:), it can be associated 
*unambiguously* with the last "if" followed by a colon (here, 
"if(foo):"), and not with the last "if" (here, "if(bar)").


Actual result:
--
Parse error. The "else" is associated with the last "if", and the 
following ":" is unexpected.


-- 
Edit bug report at http://bugs.php.net/?id=51016&edit=1
-- 
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=51016&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=51016&r=trysnapshot53
Try a snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=51016&r=trysnapshot60
Fixed in SVN:
http://bugs.php.net/fix.php?id=51016&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=51016&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=51016&r=alreadyfixed
Need backtrace:  
http://bugs.php.net/fix.php?id=51016&r=needtrace
Need Reproduce Script:   
http://bugs.php.net/fix.php?id=51016&r=needscript
Try newer version:   
http://bugs.php.net/fix.php?id=51016&r=oldversion
Not developer issue: 
http://bugs.php.net/fix.php?id=51016&r=support
Expected behavior:   
http://bugs.php.net/fix.php?id=51016&r=notwrong
Not enough info: 
http://bugs.php.net/fix.php?id=51016&r=notenoughinfo
Submitted twice: 
http://bugs.php.net/fix.php?id=51016&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=51016&r=globals
PHP 4 support discontinued:  http://bugs.php.net/fix.php?id=51016&r=php4
Daylight Savings:http://bugs.php.net/fix.php?id=51016&r=dst
IIS Stability:   
http://bugs.php.net/fix.php?id=51016&r=isapi
Install GNU Sed: 
http://bugs.php.net/fix.php?id=51016&r=gnused
Floating point limitations:  
http://bugs.php.net/fix.php?id=51016&r=float
No Zend Extensions:  
http://bugs.php.net/fix.php?id=51016&r=nozend
MySQL Configuration Error:   
http://bugs.php.net/fix.php?id=51016&r=mysqlcfg