473,387 Members | 1,540 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Existing columns vs. Null columns question

I have a get function that looks like this:

/**
* Magic function that gets properties
* @param mixed $var The property that should be retrieved
* @return mixed The value of the property. Returns null if property
doesn't exist
*/
function __get($var)
{
$special_properties = array('name');

if (!isset($this->data[$var]) && !in_array($var,$special_properties))
{
echo "Warning: $var is not a property for ".get_class($this)."!\n";
return null;
}
else{
switch ($var){
case 'name':
return $this->data['first_name'].' '.$this->data['last_name'];
break;
case 'office_phone':
case 'mobile_phone':
case 'other_phone':
return $this->to_phone_string($this->data[$var]);
break;
default:
return $this->data[$var];
}
}
}

Here's the question. Say I have a row in my database that has a null
value in the column other_phone. When it gets to the first if
statement !isset($this->data[$var]) it is going to evaluate to true
(in other words $this->data['office_phone'] is not set because it is
null). How do I evaluate if the column is merely not there instead of
not there or null?

Oct 16 '07 #1
4 1143
On 16 Oct, 14:46, GameboyHippo <jasonwthomp...@gmail.comwrote:
I have a get function that looks like this:

/**
* Magic function that gets properties
* @param mixed $var The property that should be retrieved
* @return mixed The value of the property. Returns null if property
doesn't exist
*/
function __get($var)
{
$special_properties = array('name');

if (!isset($this->data[$var]) && !in_array($var,$special_properties))
{
echo "Warning: $var is not a property for ".get_class($this)."!\n";
return null;
}
else{
switch ($var){
case 'name':
return $this->data['first_name'].' '.$this->data['last_name'];
break;
case 'office_phone':
case 'mobile_phone':
case 'other_phone':
return $this->to_phone_string($this->data[$var]);
break;
default:
return $this->data[$var];
}
}
}

Here's the question. Say I have a row in my database that has a null
value in the column other_phone. When it gets to the first if
statement !isset($this->data[$var]) it is going to evaluate to true
(in other words $this->data['office_phone'] is not set because it is
null). How do I evaluate if the column is merely not there instead of
not there or null?
If $this->data['office_phone'] is set to NULL then I would expect !
isset($this->data[$var]) to evaluate to false, because !isset($this-
>data[$var]) IS set.
Oct 16 '07 #2
On Tue, 16 Oct 2007 15:46:07 +0200, GameboyHippo
<ja************@gmail.comwrote:
How do I evaluate if the column is merely not there instead of
not there or null?
http://nl2.php.net/manual/en/functio...key-exists.php
--
Rik Wasmus
Oct 16 '07 #3
On Oct 16, 9:11 am, Captain Paralytic <paul_laut...@yahoo.comwrote:
On 16 Oct, 14:46, GameboyHippo <jasonwthomp...@gmail.comwrote:
I have a get function that looks like this:
/**
* Magic function that gets properties
* @param mixed $var The property that should be retrieved
* @return mixed The value of the property. Returns null if property
doesn't exist
*/
function __get($var)
{
$special_properties = array('name');
if (!isset($this->data[$var]) && !in_array($var,$special_properties))
{
echo "Warning: $var is not a property for ".get_class($this)."!\n";
return null;
}
else{
switch ($var){
case 'name':
return $this->data['first_name'].' '.$this->data['last_name'];
break;
case 'office_phone':
case 'mobile_phone':
case 'other_phone':
return $this->to_phone_string($this->data[$var]);
break;
default:
return $this->data[$var];
}
}
}
Here's the question. Say I have a row in my database that has a null
value in the column other_phone. When it gets to the first if
statement !isset($this->data[$var]) it is going to evaluate to true
(in other words $this->data['office_phone'] is not set because it is
null). How do I evaluate if the column is merely not there instead of
not there or null?

If $this->data['office_phone'] is set to NULL then I would expect !
isset($this->data[$var]) to evaluate to false, because !isset($this-
data[$var]) IS set.
I agree, however in practice, it doesn't work as expected. I'll check
out the other reply and see if that helps. Thanks!

Oct 16 '07 #4
On Oct 16, 9:19 am, "Rik Wasmus" <luiheidsgoe...@hotmail.comwrote:
On Tue, 16 Oct 2007 15:46:07 +0200, GameboyHippo

<jasonwthomp...@gmail.comwrote:
How do I evaluate if the column is merely not there instead of
not there or null?

http://nl2.php.net/manual/en/functio...key-exists.php
--
Rik Wasmus
Sweet! array_key_exists works wonders! Thanks!

Oct 22 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Robert Scheer | last post by:
Hi. I think I have some conceptual questions here. I have an asp.net web application up and running and now I intend to use Atlas on some of my pages. I have read that after installing Atlas, I...
2
by: iKiLL | last post by:
Hi All, My background is that i am new to C- Sharp and OOP. I have been working with it for about 2 Weeks. I do have good experionce in developing in things like VB6, COM, ASP, JavaScript and i...
0
by: frostbb | last post by:
Ok, stumped one more time, I'm trying to learn how to use a DataGridView in place of the old DataGrid control. QUESTION: How do I map the columns returned from a RunTime sql query to the columns...
13
by: =?Utf-8?B?UGV0ZXI=?= | last post by:
I want to create a new column in a datatable from two existing columns. I have no problem to create the new column using the datatable.columns.add method. The problem is the value of the new...
6
by: napatel04 | last post by:
Hi everyone, I would like to know if there is a quick query someone can help me write for the following scenario. I think I can do this with VBA but since this is suppose to be a temp. solution,...
2
by: id10t error | last post by:
Hello, I am working on a project where I read in data from a flat file using a dataset .The program than lets the user scan the barcode. The problem is when the person scans a barcode on another...
5
by: Romulo NF | last post by:
Greetings, I´m back here to show the new version of the drag & drop table columns (original script ). I´ve found some issues with the old script, specially when trying to use 2 tables with...
2
by: kostasgio | last post by:
Hello, this is my first post here, i hope i'll find this forum usefull. Although i did a search about my question, i didnt find what i need , because the question isnt exactly what it sounds. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.