473,511 Members | 16,756 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

what is the meaning

sam
What is the meaning of this operator:-
=>
Please tell about this.

Nov 28 '06 #1
11 1580

sam wrote:
What is the meaning of this operator:-
=>
Please tell about this.
Assignment - used in arrays?
http://www.php.net/manual/en/language.types.array.php

Nov 28 '06 #2
Also sprach BKDotCom:
sam wrote:
>What is the meaning of this operator:-
=>
Assignment - used in arrays?
Hm. But why the need for a special operator here? Wouldn't a simple = have
done the job just as well?

Greetings,
Thomas
Nov 28 '06 #3
NC
Thomas Mlynarczyk wrote:
>
sam wrote:
What is the meaning of this operator:-
=>
Assignment - used in arrays?

Hm. But why the need for a special operator here? Wouldn't
a simple = have done the job just as well?
Yes, but you'd have to write it differently.

Consider this simple example:

$someArray = array('field1' =1, 'field2' ='two');

If it equivalent to:

$someArray = array();
$someArray['field1'] = 1;
$someArray['field2'] = 'two';

Moreover, the second option might trigger an E_NOTICE, since
you would be trying to assign a value to a not-yet-defined member
of the array...

Cheers,
NC

Nov 28 '06 #4
NC wrote:
Thomas Mlynarczyk wrote:
>>>sam wrote:

What is the meaning of this operator:-
=>

Assignment - used in arrays?

Hm. But why the need for a special operator here? Wouldn't
a simple = have done the job just as well?


Yes, but you'd have to write it differently.

Consider this simple example:

$someArray = array('field1' =1, 'field2' ='two');

If it equivalent to:

$someArray = array();
$someArray['field1'] = 1;
$someArray['field2'] = 'two';

Moreover, the second option might trigger an E_NOTICE, since
you would be trying to assign a value to a not-yet-defined member
of the array...

Cheers,
NC
Actually, the second option is perfectly valid. It's fine to assign to
an array element which hasn't been defined yet. Just don't try to USE
an array element (or any other variable) before it's been defined.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Nov 29 '06 #5
"Thomas Mlynarczyk" <th****@mlynarczyk-webdesign.dewrote in message
news:ek*************@news.t-online.com...
Also sprach BKDotCom:
>sam wrote:
>>What is the meaning of this operator:-
=>
>Assignment - used in arrays?

Hm. But why the need for a special operator here? Wouldn't a simple = have
done the job just as well?

concider the syntax in that case:
$foo = 'bar';
$array1 = array($foo ='zap');
$array2 = array($foo = 'zap');

In the first case you'll get
$array1['bar'] = 'zap'
$foo = 'bar'

but in the second case
$array2[0] = 'zap'
$foo = 'zap'

The results are very different and the reason is clear, the = operator means
a completely different thing than =operator. To get the effect what you
want you need to have another operator. How is php going to know which one
you meant?

And remember it's used in foreach as well:

foreach($array as $key =$val) vs. foreach($array as $key = $val)

Again, very different results, I guess both would be still valid syntax,
although I'm not quite sure about the latter.

The operations that the operators perform are clearly different, that is why
there is a need for two different operators as well.

--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
sp**@outolempi.net | rot13(xv***@bhgbyrzcv.arg)
Nov 29 '06 #6
Also sprach Kimmo Laine:
[Assignment operator in arrays: =>]
>Hm. But why the need for a special operator here? Wouldn't a simple
= have done the job just as well?
consider the syntax in that case:
$array2 = array($foo = 'zap');
Ah, yes, now I see.

Thanks and greetings,
Thomas
Nov 29 '06 #7
Also sprach Jerry Stuckle:
>$someArray = array('field1' =1, 'field2' ='two');
>$someArray = array();
$someArray['field1'] = 1;
$someArray['field2'] = 'two';
Actually, the second option is perfectly valid. It's fine to assign
to an array element which hasn't been defined yet. Just don't try to
USE an array element (or any other variable) before it's been defined.
Come to think of it:
$GLOBALS['notDefinedYet']
and
global $notDefinedYet

The first would give a notice, the second one not. I thought I had read
something about this difference in the manual, but can't find it again.

Also, I have heard about a security issue concerning $GLOBALS: that in some
versions of PHP, it is (was?) possible to overwrite the complete array by
passing a request parameter 'GLOBALS' to the script. Would the global
keyword also be concerned here?

Greetings,
Thomas

Nov 29 '06 #8
Thomas Mlynarczyk wrote:
Also sprach Jerry Stuckle:

>>>$someArray = array('field1' =1, 'field2' ='two');

>>>$someArray = array();
$someArray['field1'] = 1;
$someArray['field2'] = 'two';

>>Actually, the second option is perfectly valid. It's fine to assign
to an array element which hasn't been defined yet. Just don't try to
USE an array element (or any other variable) before it's been defined.


Come to think of it:
$GLOBALS['notDefinedYet']
and
global $notDefinedYet

The first would give a notice, the second one not. I thought I had read
something about this difference in the manual, but can't find it again.

Also, I have heard about a security issue concerning $GLOBALS: that in some
versions of PHP, it is (was?) possible to overwrite the complete array by
passing a request parameter 'GLOBALS' to the script. Would the global
keyword also be concerned here?

Greetings,
Thomas
$GLOBALS['notDefinedYet'] = $x;

will not give a notice.

$x = $GLOBALS['notDefinedYet'];

will. See the difference?
And

global($notDefinedYet);

Doesn't actually use the value. It just declares it to be global.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Nov 29 '06 #9
Also sprach Jerry Stuckle:
$GLOBALS['notDefinedYet'] = $x;
will not give a notice.
$x = $GLOBALS['notDefinedYet'];
will. See the difference?
Yes, of that I was aware.
global($notDefinedYet);
Doesn't actually use the value. It just declares it to be global.
I thought

global $myVar;

was the equivalent of

if ( !isSet( $GLOBALS['myVar'] ) )
{
$GLOBALS['myVar'] = null;
}

$myVar = &$GLOBALS['myVar'];

Greetings,
Thomas
Nov 29 '06 #10
Thomas Mlynarczyk wrote:
Also sprach Jerry Stuckle:

>>$GLOBALS['notDefinedYet'] = $x;
will not give a notice.
$x = $GLOBALS['notDefinedYet'];
will. See the difference?


Yes, of that I was aware.

>>global($notDefinedYet);
Doesn't actually use the value. It just declares it to be global.


I thought

global $myVar;

was the equivalent of

if ( !isSet( $GLOBALS['myVar'] ) )
{
$GLOBALS['myVar'] = null;
}

$myVar = &$GLOBALS['myVar'];

Greetings,
Thomas

I don't think it actually sets $GLOBALS['myVar'] to null, but I could be
wrong. I use globals very rarely.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Nov 29 '06 #11
Also sprach Jerry Stuckle:
I don't think it actually sets $GLOBALS['myVar'] to null, but I could
be wrong.
Well, it seems that $GLOBALS['myVar'] is "set" somehow. At least isSet()
says so, I think. What's important to me here is that I can use something
like

global $myVar;
$this->myVar = is_int( $myVar ) ? $myVar : 0;

instead of

$this->myVar = isSet( $GLOBALS['myVar'] ) && is_int( $GLOBALS['myVar'] )
? $GLOBALS['myVar'] : 0;
I use globals very rarely.
So do I. Just for configuration variables.

Greetings,
Thomas
Nov 29 '06 #12

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

Similar topics

12
5221
by: jinal jhaveri | last post by:
Hi All, I have one question regarding circular inheritance I have 3 files 1) A.py , having module A and some other modules 2) B.py having module B and some other modules 3) C.py having...
112
10219
by: Andy | last post by:
Hi All! We are doing new development for SQL Server 2000 and also moving from SQL 7.0 to SQL Server 2000. What are cons and pros for using IDENTITY property as PK in SQL SERVER 2000? Please,...
20
3197
by: Steven T. Hatton | last post by:
I just read this in the description of how C++ is supposed to be implemented: "All external object and function references are resolved. Library components are linked to satisfy external...
17
134401
by: candy_init | last post by:
I sometimes comes across statements which invloves the use of size_t.But I dont know exactly that what is the meaning of size_t.What I know about it is that it is used to hide the platform...
7
1586
by: KevinLee | last post by:
I found that the STL.NET published with VS Beta2, but what is the meaning of STL.NET. Is it just a simple wrapper to replace the old std stl? I can find nothing new but the keyword 'Generate' to...
669
25398
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Languageâ€, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
132
4498
by: Frederick Gotham | last post by:
If we look at a programming language such as C++: When an updated Standard comes out, everyone adopts it and abandons the previous one. It seems though that things aren't so clear-cut in the C...
22
3034
by: nospam_news | last post by:
I currently get asked about my usage of "auto". What is it for? The keyword is clearly superflous here. In contrast to the huge majority of C/C++ developers I write definitions very explicitly...
4
7776
by: Virtual_X | last post by:
it's only language confusion i am non-english speaker so i heard about stream in alot of c++ tutorials ie: in iostream and in sstream headers in sstream we use the class stringstream to...
5
1604
by: =?Utf-8?B?Sm9seW5pY2U=?= | last post by:
Hi everyone, I am learning c# and i don´t understand a piece of code , can anyone explain the meaning of this code please. public class vector { public double? R = null; //I suppose this...
0
7242
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
7423
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...
0
5668
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5066
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...
0
4737
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...
0
3225
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3213
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1576
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 ...
0
447
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...

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.