473,587 Members | 2,324 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

=& when creating new object

Joe
I am just starting to use Object Oriented PHP coding, and I am seeing
quite often the following (this example taken from a wiki):

$wakka =& new Wakka($wakkaCon fig);

What exactly is the =&, and why is it different from = ?

Sep 24 '07 #1
32 2536
..oO(Joe)
>I am just starting to use Object Oriented PHP coding, and I am seeing
quite often the following (this example taken from a wiki):

$wakka =& new Wakka($wakkaCon fig);
It was required in PHP 4 to make sure that $wakka will be assigned a
reference to the created object instead of just a copy of it, which
could lead to problems in some situations.

If you just start with OOP in PHP, then you should do this with PHP 5,
where objects are always passed as references by default and you don't
have to worry about this issue anymore (at least not for objects).

Micha
Sep 24 '07 #2

"Joe" <jo*@faceh.comw rote in message
news:11******** *************@2 2g2000hsm.googl egroups.com...
>I am just starting to use Object Oriented PHP coding, and I am seeing
quite often the following (this example taken from a wiki):

$wakka =& new Wakka($wakkaCon fig);

What exactly is the =&, and why is it different from = ?
well, better syntax would have helped. it should read ' $something =
&$variable'. in this context, & means 'a reference to the memory location
where the value is stored'. without the &, it means 'a copy of the value of
the variable'.

clear as mud? rather than explain memory, let me have you do this:

$variable = 'hello';
$reference = &$variable;
$variable = 'world';
echo '<pre>' . print_r($refere nce, true) . '</pre>';
$reference = 'good-bye';
echo '<pre>' . print_r($variab le, true) . '</pre>';

unset($variable );
unset($referenc e);

$variable = 'hello';
$reference = $variable;
$variable = 'world';
echo '<pre>' . print_r($refere nce, true) . '</pre>';
$reference = 'good-bye';
echo '<pre>' . print_r($variab le, true) . '</pre>';

the first example, BY REFERENCE, means that both $variable and $reference
point to the same memory location. changing one but using the other makes no
difference - using either will have the same effect.

the second, BY VALUE, means that each variable points to two different
locations in memory. the only time they will be equal is when setting them
so. once you modify one of them, you have done so idependently of the
other - changing one has no effect on the other.

hope that makes more sense.
Sep 24 '07 #3

"Michael Fesser" <ne*****@gmx.de wrote in message
news:d5******** *************** *********@4ax.c om...
.oO(Joe)
>>I am just starting to use Object Oriented PHP coding, and I am seeing
quite often the following (this example taken from a wiki):

$wakka =& new Wakka($wakkaCon fig);

It was required in PHP 4 to make sure that $wakka will be assigned a
reference to the created object instead of just a copy of it, which
could lead to problems in some situations.

If you just start with OOP in PHP, then you should do this with PHP 5,
where objects are always passed as references by default and you don't
have to worry about this issue anymore (at least not for objects).
you've implied that byVal and byRef are restricted only to php versions and
applied only to objects. i'm sure that's not the message you want to get
across here, right?
Sep 24 '07 #4

"Steve" <no****@example .comwrote in message
news:r6******** *****@newsfe05. lga...
>
"Joe" <jo*@faceh.comw rote in message
news:11******** *************@2 2g2000hsm.googl egroups.com...
>>I am just starting to use Object Oriented PHP coding, and I am seeing
quite often the following (this example taken from a wiki):

$wakka =& new Wakka($wakkaCon fig);

What exactly is the =&, and why is it different from = ?

well, better syntax would have helped. it should read ' $something =
&$variable'. in this context, & means 'a reference to the memory location
where the value is stored'. without the &, it means 'a copy of the value
of the variable'.

clear as mud? rather than explain memory, let me have you do this:

$variable = 'hello';
$reference = &$variable;
$variable = 'world';
echo '<pre>' . print_r($refere nce, true) . '</pre>';
$reference = 'good-bye';
echo '<pre>' . print_r($variab le, true) . '</pre>';

unset($variable );
unset($referenc e);

$variable = 'hello';
$reference = $variable;
$variable = 'world';
echo '<pre>' . print_r($refere nce, true) . '</pre>';
$reference = 'good-bye';
echo '<pre>' . print_r($variab le, true) . '</pre>';

the first example, BY REFERENCE, means that both $variable and $reference
point to the same memory location. changing one but using the other makes
no difference - using either will have the same effect.

the second, BY VALUE, means that each variable points to two different
locations in memory. the only time they will be equal is when setting them
so. once you modify one of them, you have done so idependently of the
other - changing one has no effect on the other.

hope that makes more sense.
That was probably the single most unique new concept (pointers and
address-of) I had conquer when (os so many years ago) I learned C, coming
from a Fortran background as I did.

Shelly
Sep 24 '07 #5
Joe
Steve, thats a great explanation, thank you.

I have a question however. The WIKI example I'm looking at calls =&
new Wakka.... on something that has not been defined yet. It is making
a reference to something that doesnt exist? isnt it?

On Sep 24, 9:31 pm, "Steve" <no....@example .comwrote:
"Michael Fesser" <neti...@gmx.de wrote in message

news:d5******** *************** *********@4ax.c om...
.oO(Joe)
>I am just starting to use Object Oriented PHP coding, and I am seeing
quite often the following (this example taken from a wiki):
>$wakka =& new Wakka($wakkaCon fig);
It was required in PHP 4 to make sure that $wakka will be assigned a
reference to the created object instead of just a copy of it, which
could lead to problems in some situations.
If you just start with OOP in PHP, then you should do this with PHP 5,
where objects are always passed as references by default and you don't
have to worry about this issue anymore (at least not for objects).

you've implied that byVal and byRef are restricted only to php versions and
applied only to objects. i'm sure that's not the message you want to get
across here, right?

Sep 24 '07 #6

"Shelly" <sh************ @asap-consult.comwrot e in message
news:13******** *****@corp.supe rnews.com...
>
"Steve" <no****@example .comwrote in message
news:r6******** *****@newsfe05. lga...
>>
"Joe" <jo*@faceh.comw rote in message
news:11******* **************@ 22g2000hsm.goog legroups.com...
>>>I am just starting to use Object Oriented PHP coding, and I am seeing
quite often the following (this example taken from a wiki):

$wakka =& new Wakka($wakkaCon fig);

What exactly is the =&, and why is it different from = ?

well, better syntax would have helped. it should read ' $something =
&$variable'. in this context, & means 'a reference to the memory location
where the value is stored'. without the &, it means 'a copy of the value
of the variable'.

clear as mud? rather than explain memory, let me have you do this:

$variable = 'hello';
$reference = &$variable;
$variable = 'world';
echo '<pre>' . print_r($refere nce, true) . '</pre>';
$reference = 'good-bye';
echo '<pre>' . print_r($variab le, true) . '</pre>';

unset($variabl e);
unset($referen ce);

$variable = 'hello';
$reference = $variable;
$variable = 'world';
echo '<pre>' . print_r($refere nce, true) . '</pre>';
$reference = 'good-bye';
echo '<pre>' . print_r($variab le, true) . '</pre>';

the first example, BY REFERENCE, means that both $variable and $reference
point to the same memory location. changing one but using the other makes
no difference - using either will have the same effect.

the second, BY VALUE, means that each variable points to two different
locations in memory. the only time they will be equal is when setting
them so. once you modify one of them, you have done so idependently of
the other - changing one has no effect on the other.

hope that makes more sense.

That was probably the single most unique new concept (pointers and
address-of) I had conquer when (os so many years ago) I learned C, coming
from a Fortran background as I did.
and i bet it opened up an entirely new world to your mind to set off
on...one that is constructed much more simply that without it, right? yeah,
that was a big deal for me too...going from BASIC to C. before BASIC, i
worked directly with memory registers in PLC's. i just thought i'd have to
give up that ability when i got into BASIC. then i saw the construct and an
example in a C programming book. BINGO, i had it all again! what's funny is
the book explained it poorly (too verbose), however the best example i found
yeeeaaaarrrrsss s later was on php.net in their docs. a single four line
example that showed what was going on.
Sep 24 '07 #7
Shelly wrote:
"Steve" <no****@example .comwrote in message
news:r6******** *****@newsfe05. lga...
>"Joe" <jo*@faceh.comw rote in message
news:11******* **************@ 22g2000hsm.goog legroups.com...
>>I am just starting to use Object Oriented PHP coding, and I am seeing
quite often the following (this example taken from a wiki):

$wakka =& new Wakka($wakkaCon fig);

What exactly is the =&, and why is it different from = ?
well, better syntax would have helped. it should read ' $something =
&$variable'. in this context, & means 'a reference to the memory location
where the value is stored'. without the &, it means 'a copy of the value
of the variable'.

clear as mud? rather than explain memory, let me have you do this:

$variable = 'hello';
$reference = &$variable;
$variable = 'world';
echo '<pre>' . print_r($refere nce, true) . '</pre>';
$reference = 'good-bye';
echo '<pre>' . print_r($variab le, true) . '</pre>';

unset($variabl e);
unset($referen ce);

$variable = 'hello';
$reference = $variable;
$variable = 'world';
echo '<pre>' . print_r($refere nce, true) . '</pre>';
$reference = 'good-bye';
echo '<pre>' . print_r($variab le, true) . '</pre>';

the first example, BY REFERENCE, means that both $variable and $reference
point to the same memory location. changing one but using the other makes
no difference - using either will have the same effect.

the second, BY VALUE, means that each variable points to two different
locations in memory. the only time they will be equal is when setting them
so. once you modify one of them, you have done so idependently of the
other - changing one has no effect on the other.

hope that makes more sense.

That was probably the single most unique new concept (pointers and
address-of) I had conquer when (os so many years ago) I learned C, coming
from a Fortran background as I did.

Shelly

php references have nothing to do with C-alike pointers.

Please read the chapter called "references are not pointers" in the manual.

--
gosha bine

extended php parser ~ http://code.google.com/p/pihipi
blok ~ http://www.tagarga.com/blok
Sep 24 '07 #8
..oO(Steve)
>you've implied that byVal and byRef are restricted only to php versions and
applied only to objects.
Have I? References are explained in detail in the manual and the OP was
explicitly talking about OOP. But OK, I got your point.

Micha
Sep 24 '07 #9

"Joe" <jo*@faceh.comw rote in message
news:11******** **************@ r29g2000hsg.goo glegroups.com.. .
Steve, thats a great explanation, thank you.

I have a question however. The WIKI example I'm looking at calls =&
new Wakka.... on something that has not been defined yet. It is making
a reference to something that doesnt exist? isnt it?
kind of, but no.

think of it as if you read that example from right to left. that is how most
variable assignments should be read by you when confusion sets in. anyway,
first the object is created by php. then php, through the & instruction,
returns the 'pointer' of where that object is in memory to the variable
getting the assignment.

make sense? right to left.

let me know.
Sep 24 '07 #10

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

Similar topics

4
3728
by: Hugh Cowan | last post by:
Hello, I don't program full-time (anymore), but I do try and stay on-top of the latest technologies and like most are always trying to upgrade my skills and remain current (as much as is possible). Most of my programming these days involves using PHP for creating script files for automating tasks and procedures (locally), and also for...
11
3614
by: BoonHead, The Lost Philosopher | last post by:
I think the .NET framework is great! It's nice, clean and logical; in contradiction to the old Microsoft. It only saddens me that the new Microsoft still doesn't under stand there own rules when it comes to file paths. A lot of Microsoft installers for example, and also installers of other companies, do not work because they handle...
0
1636
by: James Thurley | last post by:
I'm creating an XmlDocument manually, adding content using the Xml classes such as XmlElement and XmlText, and I then write it out as as "text/xml" to the HttpResponse.Output TextWriter object under IIS. The problem I get is when I create an XmlElement with an XmlAttribute whose value contains the "&" character. When the xml is written the...
4
3055
by: debbie | last post by:
Well I'm finally trying out class modules...I have a great book I'm using but its ADO and I use DAO so it's a challenge for me...I've looked most of today, in my book and here but can not find an answer. Is it possible to use the class I've created to fill a continuous form? Not finding any information leads me to believe that it can't be...
2
1783
by: Chris Murphy via DotNetMonster.com | last post by:
Hey guys, I've been hitting a brick wall with a problem I've come accross in developing an application. Background: The application uses one primary class that I'm trying to implement with the singleton pattern in mind. The design pattern seems to be working properly (complex and simple variations of it) Serialzation/Deserialzation seems...
3
8273
by: wizzbangca | last post by:
Hi everyone. Having problems with a utility I am writing for work. The previous IT Director thoughtfully allowed 3 (2000, xp, 2003) versions of outlook to be installed rather than 1. Now I need the utility to work for all 3 versions. A previous post suggested creating objects to detect the version of outlook, which I tried with success. ...
2
2594
by: 1944USA | last post by:
I am re-architecting a C# application written as a multithreaded Windows Service and trying to squeeze every bit of performance out of it. 1) Does the thread that an object is instantiated on have any impact on its performnce? Example: if I instantiate object "X" on thread "A" pass a reference of "X" to Thread "B" and then have "B"...
0
5546
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted ******************************************************** For this teeny job, please refer to: http://feeds.reddit.com/feed/8fu/?o=25
0
7178
by: Tarik Monem | last post by:
I have been working on an all AJAX/DOM web site which is set to go live today and I thought I'd share my discoveries with all of you whom have helped me when I have encountered different issues along the way. First, deep linking is not something that a completely AJAX web site should be able to do by it's very nature of everything being on one...
5
13759
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 drag&drop on the same page (which was not possible). Now i´ve a new concept of the script, more object oriented. I´ve also commented the whole code so you...
0
7918
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8340
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...
1
7967
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...
0
8220
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...
0
6621
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5713
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...
0
5392
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...
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1185
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...

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.