473,385 Members | 1,409 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,385 software developers and data experts.

how control struct evaluate

Hi,

$PHONETIC is an array of strings. How can !$PHONETIC['d'], in the case
below, evalutae to true. It is a string not a boolean. It would make more
sense if it evalutated to null.

Thanks Mike

<?php

$PHONETIC = array('a' => 'alpha', 'b' => 'bravo', 'c' => 'charlie');

if(!$PHONETIC['d']):
echo 'true';
else:
echo 'false';
endif

?>


----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Aug 1 '05 #1
6 2309
Michael G wrote:
$PHONETIC is an array of strings. How can !$PHONETIC['d'], in the case
below, evalutae to true. It is a string not a boolean. It would make more
sense if it evalutated to null. $PHONETIC = array('a' => 'alpha', 'b' => 'bravo', 'c' => 'charlie');


Actually, I think it does. Try:

echo @gettype($PHONETIC['d']);

And when you use NULL in a boolean expression, it evaluates to false
Aug 1 '05 #2

"jamen" <jamen@invalid> wrote in message
news:42*********************@dtext02.news.tele.dk. ..
Michael G wrote:
$PHONETIC is an array of strings. How can !$PHONETIC['d'], in the case
below, evalutae to true. It is a string not a boolean. It would make more
sense if it evalutated to null.

$PHONETIC = array('a' => 'alpha', 'b' => 'bravo', 'c' => 'charlie');


Actually, I think it does. Try:


I know it does, my question is why does it. It seems like an abuse of the
syntax but according to the link below it is not at least in the named
cases.

The following link states a number of cases for boolean conversion. It does
state that an array with zero elements will be converted to FALSE but not
the case above where an array element is not set. Maybe I am reading too
much into it...

http://us2.php.net/manual/en/languag...oolean.casting
Mike

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Aug 1 '05 #3
"Michael G" <mi****@montana.com> kirjoitti
viestissä:42**********@spool9-west.superfeed.net...
Hi,

$PHONETIC is an array of strings. How can !$PHONETIC['d'], in the case
below, evalutae to true. It is a string not a boolean. It would make more
sense if it evalutated to null.

Thanks Mike

<?php

$PHONETIC = array('a' => 'alpha', 'b' => 'bravo', 'c' => 'charlie');

if(!$PHONETIC['d']):
echo 'true';
else:
echo 'false';
endif

?>

Why would it be a string? It is un undefined variable (undefined array
indexs to be precise). If you call it with a boolean operator, bolean is
assumed, just as well false is assumed since it had no value before. !false
evaluates true quite logically.

$PHONETIC is not an array of strings by no definition. Sure, it contains
three variables that happen to be strings, but that still doesn't meka any
difference. It is simply an array that can hold any kinds of variable types.

There are other tests, that you might find useful. isset() tells you wether
a variable (or array reference) is defined or not. gettype() tells yuo what
is the type of the given variable.

--
SETI @ Home - Donate your cpu's idle time to science.
Further reading at <http://setiweb.ssl.berkeley.edu/>

Soulman <et****************@5P4Mgmail.com>
Aug 1 '05 #4
Michael G wrote:
The following link states a number of cases for boolean conversion. It does
state that an array with zero elements will be converted to FALSE but not
the case above where an array element is not set. Maybe I am reading too
much into it...

http://us2.php.net/manual/en/languag...oolean.casting


Well, it clearly states:

When converting to boolean, the following values are considered FALSE:

* the special type NULL (including unset variables)
Aug 1 '05 #5

"Kimmo Laine" <et*******************@Mgmail.com> wrote in message
news:dc**********@phys-news1.kolumbus.fi...
"Michael G" <mi****@montana.com> kirjoitti
viestissä:42**********@spool9-west.superfeed.net... <snipped>If you call it with a boolean operator, bolean is
assumed, just as well false is assumed since it had no value before.
!false evaluates true quite logically.


I have to keep reminding myself that php is not typed explicitly but rather
by context. (I think you can set a type though.) I am so used to working
with strongly typed languages. Thanks for your input.

Mike

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Aug 1 '05 #6

"jamen" <jamen@invalid> wrote in message
news:42*********************@dtext02.news.tele.dk. ..
Michael G wrote:
The following link states a number of cases for boolean conversion. It
does state that an array with zero elements will be converted to FALSE
but not the case above where an array element is not set. Maybe I am
reading too much into it...

http://us2.php.net/manual/en/languag...oolean.casting


Well, it clearly states:

When converting to boolean, the following values are considered FALSE:

* the special type NULL (including unset variables)


Thanks. I missed that. Read right over it.
Mike

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Aug 1 '05 #7

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

Similar topics

5
by: Michael | last post by:
Ive been programming for some time now, so i wanted to get into graphics, but i wanted to see if I could make a Picture Viewer. I have no experience with the picture control, ive tryed the MSDN...
9
by: ckerns | last post by:
I want to loop thru an array of controls,(39 of them...defaults = 0). If value is null or non-numeric I want to assign the value of "0". rowString = "L411" //conrol name if (isNaN(eval...
19
by: Martin Pohlack | last post by:
Hi, I have a funtion which shall compute the amount for a later malloc. In this function I need the sizes of some struct members without having an instance or pointer of the struct. As...
4
by: michael | last post by:
I found follow function in the Linux kernel (kernel/resource.c) static int r_show(struct seq_file *m, void *v) { struct resource *root = m->private; struct resource *r = v, *p; int width =...
0
by: Yuriy | last post by:
Hello! I need create a server control and dynamicly determine that control on the form. In JavaScript exist function eval() which allows to evaluate a control on the form. For example...
6
by: Nick Stansbury | last post by:
Hi, I have a loop running on Page_PreRender that sets a number of controls to invisible based on a set of criteria. Before I do this however, I set all of the drop down lists to be visible with...
3
by: VladimirT | last post by:
in vba is used windows script control 1.0 for molded got from txtFunction as possible do this in vb.net? thank you I have written code but he does not work Function FunctionEval(ByVal X As...
3
by: Steven T. Hatton | last post by:
I'm trying to work out a design for dynamically determining file types, and for generating new files of a given type. I'm curious to know what others think of my current strategy. Is it "so...
74
by: Zytan | last post by:
I have a struct constructor to initialize all of my private (or public readonly) fields. There still exists the default constructor that sets them all to zero. Is there a way to remove the...
7
Wing
by: Wing | last post by:
I was wondering if it is possible to evaluate a variable to determine if the variable is a control on the current or other form? Here is what I am currently looking at. I have two date fields that...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.