473,387 Members | 1,678 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.

please explain or refer: $string = isset($xyz) ? $xyz : "something else";

"$string = isset($xyz) ? $xyz : "something else";"

Hello, someone gave code like this in another thread. I understand (by
inference) what it does, but have not found any documentation on this
type of syntax.

Any one have links to this shortuct(?) syntax and other types of
syntax?

thanks
j

Jul 23 '05 #1
5 1968
ahh, sorry, wrong group

all apologies
j

Jul 23 '05 #2
"juglesh" <ju*********@hotmail.com> writes:
"$string = isset($xyz) ? $xyz : "something else";"

Hello, someone gave code like this in another thread. I understand (by
inference) what it does, but have not found any documentation on this
type of syntax.

Any one have links to this shortuct(?) syntax and other types of
syntax?


Well, the definitive guide would be ECMA 262, 3rd edition:
<URL:http://www.ecma-international.org/publications/standards/Ecma-262.htm>

For less ... detailed ... descriptions, you can use:
JScript:
<URL:http://msdn.microsoft.com/library/en-us/script56/html/js56jslrfjscriptlanguagereference.asp>
JavaScript 1.1:
<URL:http://wp.netscape.com/eng/mozilla/3.0/handbook/javascript/>
JavaScript 1.5:
<URL:http://www.croczilla.com/~alex/reference/javascript_ref/>

In all these, the "...?...:..." syntax is described under "operators"
(beacuse that is what it is :)

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #3
juglesh wrote:
"$string = isset($xyz) ? $xyz : "something else";"

Hello, someone gave code like this in another thread. I understand (by
inference) what it does, but have not found any documentation on this
type of syntax.

Any one have links to this shortuct(?) syntax and other types of
syntax?

thanks
j


javascript version of PHP's isset would be:

typeof(xyz)!='undefined'

Therefore:

string = typeof(xyz)!='undefined' ? xyz : 'something else';

--
Justin Koivisto - ju****@koivi.com
http://koivi.com
Jul 23 '05 #4
Justin Koivisto wrote:
<snip>
javascript version of PHP's isset would be:

typeof(xyz)!='undefined'

Therefore:

string = typeof(xyz)!='undefined' ? xyz : 'something else';


Except that in javascript - typeof - is an operator so its operand does
not need to be parenthesised. Though doing so is harmless, it is just
potentially misleading as to the nature of - typeof - because the
results resemble a function call.

Richard.
Jul 23 '05 #5
Justin Koivisto wrote:
javascript version of PHP's isset would be:

typeof(xyz)!='undefined'


No, because PHP's isset()

,-<http://php.net/isset>
| Returns TRUE if var exists; FALSE otherwise.

"Exists" has to be read as "has been defined, its value is not NULL and
unset() was not applied on it.":

,-<ibid.>
| If a variable has been unset with unset(), it will no longer be set.
| isset() will return FALSE if testing a variable that has been set to
| NULL.

But in JS, there are fundamental differences:

1. An already instantiated variable may have/become the
value of `undefined':

var x;
alert(typeof x); // `undefined'
alert(x); // `undefined' or nothing

var y = y;
alert(typeof y); // `undefined'
alert(y); // `undefined'

2. An already instantiated variable may be undefined by
having the `delete' operator applied on it, provided
that it was not declared (`var' keyword was not used):

z = 2;
alert(typeof z); // `number'
delete z;
alert(typeof z); // `undefined'
alert(z); // ReferenceError

3. A named function argument may be not supplied. In
that case, its value is, by definition :), `undefined':

function foo(a, b)
{
alert([typeof a, typeof b]); // `number,undefined'
}
foo(42);

4. Although `null' in JS is a special value of the internal Null type,

,-<ECMAScript 3>
| 4.3.11 Null Value
| The null value is a primitive value that represents
| the null, empty, or non-existent reference.
|
| 4.3.12 Null Type
| The type Null has exactly one value, called null.

which it has in common with PHP (where NULL is the sole value of
the NULL type), it yields

var x = null;
alert(typeof x); // `object'

This is most certainly an attribution to the fact that a reference
always refers to an object or not.
Conclusion:

Besides risking a ReferenceError (and hopefully catching it with exception
handling), there is no way in JS to determine whether a variable/property
was defined or not; it is only possible to determine whether it yields
`undefined' (the sole value of the internal Undefined type) or `null', or
not.
PointedEars
--
When the power of love overcomes the love
of power, the world will know peace.
-- Jimi Hendrix
Jul 23 '05 #6

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

Similar topics

8
by: Yannick Turgeon | last post by:
Hello all, We are currently changing our web server and, in the process, updating PHP version from 4.3.0 to 4.3.5. The problem we've got is that our PHP applications generate errors saying that...
14
by: juglesh | last post by:
"$string = isset($xyz) ? $xyz : "something else";" Hello, someone gave code like this in another thread. I understand (by inference) what it does, but have not found any documentation on...
23
by: Invalid User | last post by:
While trying to print a none empty list, I accidentaly put an "else" statement with a "for" instead of "if". Here is what I had: if ( len(mylist)> 0) : for x,y in mylist: print x,y else:...
8
by: Sam Sungshik Kong | last post by:
Hello! I use Python for ASP programming. I found something weird. Response.Write(Request("something")) It draws "None" when there's no value for something. Actually I expect "" instead of...
4
by: Marcin Dobrucki | last post by:
I've been having some problems with a parse error that I can't figure out (PHP 4.3.11 on Solaris9). Sample code: <?php // getting strange parse errors on this class A { var $value; function...
44
by: Tolga | last post by:
As far as I know, Perl is known as "there are many ways to do something" and Python is known as "there is only one way". Could you please explain this? How is this possible and is it *really* a...
35
by: pinkfloydhomer | last post by:
How do I check if a string contains (can be converted to) an int? I want to do one thing if I am parsing and integer, and another if not. /David
2
by: naughtybynature | last post by:
<html> <head> <title>Search Questions</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php $query = '';
1
by: naughtybynature | last post by:
<html> <head> <title>Search Questions</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php $query = '';
2
MatthewML
by: MatthewML | last post by:
I am attempting to insert a custom AfterUpdate Event Procedure into a text box on a form that I am designing in MS Access 2000. This text box contains the e-mail address of the referenced contact,...
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...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.