473,776 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2332
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($PHONE TIC['d']);

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

"jamen" <jamen@invali d> wrote in message
news:42******** *************@d text02.news.tel e.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.ber keley.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@invali d> wrote in message
news:42******** *************@d text02.news.tel e.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
2267
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 tutorial for the control. If the code to use it in is in Basic, dont bother sending it. Nor do i have much experience with the "Open" dialog box.
9
2935
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 ("document.forms."+rowString+".value")) == true ) { //this alert works if the value is a letter,i.e,"a" alert("You have entered an non-numeric value.\nEnter a number in the appropriate box.");
19
9237
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 "sizeof(int)" is legal I assumed "sizeof(struct x.y)" to be legal too. But is is not: #include <dirent.h>
4
2147
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 = root->end < 0x10000 ? 4 : 8; int depth; for (depth = 0, p = r; depth < MAX_IORES_LEVEL; depth++, p =
0
1104
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 eval('document.myform'. + inputcontrol.name + '.checked=true') find out which control was send as a input parameter. I know vb.net would not allows control array. Do we have something that looks like eval() in JavaScript. Thank you.
6
2038
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 a straightforward recursive loop. Now - I'm really muddled by this - why does this: If TypeOf Ctl Is DropDownList Then Ctl.Visible = true End If
3
4557
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 Double) As Double ScriptControl.ExecuteStatement("X=" & X)
3
1621
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 einfach wie möglich machen, aber nicht einfacher" or "Rube Goldberg"? The first part of this has to do with a technique used in the C++ Standard Library, so I suspect the purist will not have any objection. It's the approach used to build the...
74
16036
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 creation of this implicit default constructor, to force the creation of a struct via my constructor only? Zytan
7
2128
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 are using a calendar control. Depending upon which date field opened the Calendar Control, I want the date to be passed back to that control. I would prefer not to have two Calendar Controls. Here is what I have attempted so far. Private Sub...
0
9464
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10120
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10061
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9923
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7471
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6722
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5493
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4031
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2860
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.