|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-06-02 21:19 UTC] ernesto_sanz at hotmail dot com
Description:
------------
I'm using Ubuntu Feisty Fawn 7.04 with Apache with PHP 5.2.4 and Postgres v.8.2.4.
I have noticed that, when querys are run, logical variables are not correctly assigned.
E.g. being 'lists' the table defined by the SQL sentence:
CREATE TABLE lists
(
active boolean NOT NULL DEFAULT true,
reference serial NOT NULL,
caducated boolean NOT NULL DEFAULT false,
name character varying(100) NOT NULL,
...
)
and the PHP code
// creation of the SQL sentence
$consulta="SELECT * FROM lists WHERE ((referencie=".$mykey.") AND
(active=true))";
// Execution
$result = pg_query($consulta)
or die('Error in SQL query:'.pg_last_error());
if (pg_num_rows($resultado)>0) { {
$line = pg_fetch_array($result, null, PGSQL_ASSOC);
if ($line["caducated"]==true)
{ ... -code executed if condition=true- }
else
{ ... -code executed if condition=false- }
...
I realized that the 'else' code was executed ALWAYS. It did not matter if the condition
was $line["caducated"]==True, or TRUE, or 1, or False or FALSE or 0.
I noticed that logical variables are assigned to 't' or 'f' instead of 'true' or 'false' (or numbers)
(although their type -boolean- is correct- and, that the only way to execute correctly the 'if' sentence
is by typing "if ($line["caducated"]==t)" (or "$line["caducated"]==f") which violates the reference syntax
of PHP, that states that to specify a boolean literal we have to use keywords TRUE or FALSE (both case-insensitive).
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 06:00:02 2025 UTC |
Description: ------------ I'm using Ubuntu Feisty Fawn 7.04 with Apache with PHP 5.2.4 and Postgres v.8.2.4. I have noticed that, when querys are run, logical variables are not correctly assigned. E.g. being 'lists' the table defined by the SQL sentence: CREATE TABLE lists ( active boolean NOT NULL DEFAULT true, reference serial NOT NULL, caducated boolean NOT NULL DEFAULT false, name character varying(100) NOT NULL, ... ) and the PHP code // creation of the SQL sentence $consulta="SELECT * FROM lists WHERE ((referencie=".$mykey.") AND (active=true))"; // Execution $result = pg_query($consulta) or die('Error in SQL query:'.pg_last_error()); if (pg_num_rows($resultado)>0) { { $line = pg_fetch_array($result, null, PGSQL_ASSOC); if ($line["caducated"]==true) { ... -code executed if condition=true- } else { ... -code executed if condition=false- } ... I realized that the 'else' code was executed ALWAYS. It did not matter if the condition was $line["caducated"]==True, or TRUE, or 1, or False or FALSE or 0. I noticed that logical variables are assigned to 't' or 'f' instead of 'true' or 'false' (or numbers) and their type is not correct (the result of gettype($line["caducated"]) is "string"- , so, the only way to execute correctly the 'if' sentence is by typing "if ($line["caducated"]=='t')" (or "$line["caducated"]=='f'") which violates the reference syntax of PHP, that states that to specify a boolean literal we have to use keywords TRUE or FALSE (both case-insensitive). Also, sometimes, asignation of variables inside the if or else blocks is made in a wrong way.