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

Object references... i simply don't understand it at all ;)

Hello!

I can't see any difference between:

$MyObject = new Object();
and
$MyObject =& new Object();

I used to think that if I use =&, I will be able to change variables of
the class and each new object created after that from the modified class
will have new, modified variables - but that seems not to be true...

I use PHP5 - is it the problem?
Jul 17 '05 #1
6 1437
"kajaman (a.k.a. Hubert ŁTpicki ;))" <hu*****@wp.pl> wrote in message
news:cf**********@nemesis.news.tpi.pl...
$MyObject = new Object();
and
$MyObject =& new Object();

I used to think that if I use =&, I will be able to change variables of
the class and each new object created after that from the modified class
will have new, modified variables - but that seems not to be true...


no if you add:

$AnotherMyObject = & $MyObject;

than changing $AnotherObject will also change $MyObject and other way
around.

rush
--

http://www.templatetamer.com/
Jul 17 '05 #2
rush wrote:

$AnotherMyObject = & $MyObject;

than changing $AnotherObject will also change $MyObject and other way
around.


Yes! And I understand it! But... Why people use:
$MyObject =& new Object
while it seems to work exacly the same as:
$MyObject = new Object...
strange :-/
Jul 17 '05 #3
.oO(kajaman (a.k.a. Hubert ??picki ;)))
Yes! And I understand it! But... Why people use:
$MyObject =& new Object
while it seems to work exacly the same as:
$MyObject = new Object...


Only in PHP5, it uses references by default. In PHP4 it's a difference.

Micha
Jul 17 '05 #4
kajaman (a.k.a. Hubert Łępicki ;)) wrote:
rush wrote:

$AnotherMyObject = & $MyObject;

than changing $AnotherObject will also change $MyObject and other way
around.

Yes! And I understand it! But... Why people use:
$MyObject =& new Object


PHP4: creates a new Object then points $MyObject at it
while it seems to work exacly the same as:
$MyObject = new Object...


PHP4: creates a new Object then copies the contents of same into
$MyObject (MyObject is a copy)

In practical terms you end up with the same result. However you have a
spare object floating around to be cleaned up by the garbage collector.
Jul 17 '05 #5
kajaman (a.k.a. Hubert ??picki ;)) schrieb:
Yes! And I understand it! But... Why people use:
$MyObject =& new Object
while it seems to work exacly the same as:
$MyObject = new Object...


It's the same in PHP5.

In PHP4 it is different:

$MyObject = &new Object;
creates a new instance and $MyObject get's a reference to it.

$MyObject = new Object;
creates a new instance and copies it to $MyObject.

Regards,
Matthias
Jul 17 '05 #6
Kevin Thorpe wrote:
kajaman (a.k.a. Hubert Łępicki ;)) wrote:
rush wrote:

$AnotherMyObject = & $MyObject;

than changing $AnotherObject will also change $MyObject and other way
around.


Yes! And I understand it! But... Why people use:
$MyObject =& new Object

PHP4: creates a new Object then points $MyObject at it
while it seems to work exacly the same as:
$MyObject = new Object...

PHP4: creates a new Object then copies the contents of same into
$MyObject (MyObject is a copy)

In practical terms you end up with the same result. However you have a
spare object floating around to be cleaned up by the garbage collector.

Thank you very much, now I see it clear :).
Jul 17 '05 #7

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

Similar topics

28
by: Daniel | last post by:
Hello =) I have an object which contains a method that should execute every x ms. I can use setInterval inside the object construct like this - self.setInterval('ObjectName.methodName()',...
4
by: Mark D. Anderson | last post by:
About a month ago Richard Cornford did an interesting analysis of a memory leak in jscript (internet explorer) when there are "circular" references between DOM objects and (real) jscript objects:...
33
by: JKop | last post by:
I understand variables/objects and pointer variables perfectly: int X = 5; int* pX = &X; *pX = 4; int** ppX = &pX:
6
by: Martin | last post by:
I'd like to be able to get the name of an object instance from within a call to a method of that same object. Is this at all possible? The example below works by passing in the name of the object...
5
by: Michael Moreno | last post by:
Hello, In a class I have this code: public object Obj; If Obj is a COM object I would like to call in the Dispose() method the following code: ...
26
by: yb | last post by:
Hi, Is there a standard for the global 'window' object in browsers? For example, it supports methods such as setInterval and clearInterval, and several others. I know that w3c standardized...
17
by: Divick | last post by:
Hi, I am designing an API and the problem that I have is more of a design issue. In my API say I have a class A and B, as shown below class A{ public: void doSomethingWithB( B * b) { //do...
32
by: Joe | last post by:
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($wakkaConfig); What exactly is the =&, and...
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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...
0
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...
0
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 projectplanning, coding, testing,...

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.