php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #9267 vars are set to "" instead of NULL
Submitted: 2001-02-14 17:06 UTC Modified: 2001-02-25 06:12 UTC
From: phanto@php.net Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 4.0.4pl1 OS: win2k
Private report: No CVE-ID: None
 [2001-02-14 17:06 UTC] phanto@php.net
don't know if this is only related to the mssql extension, but when i retrieve a NULL - field from the database the var will be set to "" or 0 or whatever in php.

is_null() returns false.

harald.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-02-22 05:26 UTC] stas@php.net
Could you provide a short example of a code that reproduces
this?
 [2001-02-22 13:30 UTC] phanto@php.net
<?php
$db = mssql_connect("localhost", "xxx", "yyy");
mssql_select_db("zzz", $db);

$result = mssql_query("select NULL as test", $db);

mssql_fetch_row($result);
$blah = mssql_result($result, 0, "test");

$huh = NULL;


echo is_null($blah);		// false
var_dump($blah);		// bool(false)

echo is_null($huh);		// true
var_dump($huh);			// NULL
?>


 [2001-02-24 12:14 UTC] jmoore@php.net
This seems due to PHP assuming MySQL's return values are strings, which point it is converted into an empty sting. Probably your best bet is to test for a "". I think this behaviour is documented somewhere.

James
 [2001-02-25 06:12 UTC] phanto@php.net
i think this is not an acceptable behaviour. "" could be everything, an empty string, an integer field with the value null or even a field set to NULL.
as you obviously noticed we are talking from database interfaces in general, not only mysql (as you can see we where talking about mssql in detail).

at least i would make this a feature request.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 13:01:29 2024 UTC