473,788 Members | 2,848 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP 5.0 passes objects by reference automatically?

Do I understand correctly that in PHP 5.0 objects will be passed by
reference (by handle, they say) automatically, not as a copy, as
happens with most PHP variables?
Jul 16 '05 #1
3 2194
Hello,

On 07/03/2003 07:33 PM, Toni Schornboeck wrote:
lawrence wrote:
Do I understand correctly that in PHP 5.0 objects will be passed by
reference (by handle, they say) automatically, not as a copy, as
happens with most PHP variables?

That's right.
It will be like in Java - variables are just references (or like Zend
call them: handles) to objects.
This will be a big performance improvement!


It is not a real performance improvement. You could always do that in
PHP 4, except that you needed to use the & operator to avoid copying
like this:

$my_object = &new my_class;
--

Regards,
Manuel Lemos

Free ready to use OOP components written in PHP
http://www.phpclasses.org/

Jul 16 '05 #2
"Toni Schornboeck" <to**@schornboe k.net> wrote in message
news:3f******** *************** @newsreader01.h ighway.telekom. at...
lawrence wrote: [snip snip] is it like java where it would print 5? or does PHP5 is smarter and
prints 7?


5 ... (apache2+php5b1 )
Jul 16 '05 #3
Unless I am missing something in this code snippet, there isn't any
language that would ever print back 7 since the method Foo is never
invoked. This isn't a property of the language, instead its the
behaviour of you code.

Wes Bailey
Toni Schornboeck <to**@schornboe k.net> wrote in message
news:<3f******* *************** *@newsreader01. highway.telekom .at>...
lawrence wrote:
Do I understand correctly that in PHP 5.0 objects will be passed by
reference (by handle, they say) automatically, not as a copy, as
happens with most PHP variables?


That's right.
It will be like in Java - variables are just references (or like Zend
call them: handles) to objects.
This will be a big performance improvement!

I haven't had time to test PHP5, so could someone test this code:
class Test
{
public $i;
function __construct($i)
{
$this->i=$i;
}
}

function foo($obj)
{
$obj=new Test(7);
}

$obj=new Test(5);
echo $obj->i;

is it like java where it would print 5? or does PHP5 is smarter and
prints 7?

Jul 16 '05 #4

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

Similar topics

5
9501
by: Jan Pieter Kunst | last post by:
(apologies if this message is a duplicate -- my news server seems to have problems) Greetings, When using PHP 4, this: // ex. 1 class A { function A(&$obj) {
16
3319
by: Paul Rubin | last post by:
I've had this recurring half-baked desire for long enough that I thought I'd post about it, even though I don't have any concrete proposals and the whole idea is fraught with hazards. Basically I wish there was a way to have persistent in-memory objects in a Python app, maybe a multi-process one. So you could have a persistent dictionary d, and if you say d = Frob(foo=9, bar=23) that creates a Frob instance and stores it in d. Then if...
0
1358
by: Tolga Erdogus | last post by:
I am building a thin client winform app which calls data manipulation methods of a web service and the resulting dataset is remoted back to the client. My question is, when I set the datasource and member properties of my data bound objects on my client to a local dataset reference, how do I copy the remoted dataset in to that dataset reference? The reason why I ask is that this way, I can set all the datsources of my client's...
0
17818
by: Nashat Wanly | last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaskdr/html/askgui06032003.asp Don't Lock Type Objects! Why Lock(typeof(ClassName)) or SyncLock GetType(ClassName) Is Bad Rico Mariani, performance architect for the Microsoft® .NET runtime and longtime Microsoft developer, mentioned to Dr. GUI in an e-mail conversation recently that a fairly common practice (and one that's, unfortunately, described in some of our...
2
2013
by: Mel | last post by:
This may be a stupid question, but here goes... I have created a NameValueCollection in my website's application state. If, during a page request, I add a string key and string value to the collection, how are they stored? Strings are objects so I'm really only passing references, right? Now I assume that request handlers run in different threads with their own memory spaces, and when the request ends, the memory space is unaloted,...
7
8224
by: Jo | last post by:
Hi, How can i differentiate between static and dynamic allocated objects? For example: void SomeFunction1() { CObject *objectp = new CObject; CObject object;
27
2568
by: SasQ | last post by:
Hello. I wonder if literal constants are objects, or they're only "naked" values not contained in any object? I have read that literal constants may not to be allocated by the compiler. If the Standard is saying that "object is a region of storage", I deduce from that that literal constants aren't objects because they may not be alocated as regions of storage in the memory.
167
8357
by: darren | last post by:
Hi I have to write a multi-threaded program. I decided to take an OO approach to it. I had the idea to wrap up all of the thread functions in a mix-in class called Threadable. Then when an object should run in its own thread, it should implement this mix-in class. Does this sound like plausible design decision? I'm surprised that C++ doesn't have such functionality, say in its STL. This absence of a thread/object relationship in...
29
2392
by: Jerry Spence1 | last post by:
I'm rather confused as to whether something should be disposed of, or not. What is the general rule? How can you be sure of doing the right thing? I've heard about disposing unmanaged resources but what is an unmanaged resource? Does everything need disposing? I've been using Webrequest, Webresponse, Streamreaders etc. How can I be sure of what needs disposing? Do these get automatically get disposed of at the end of the procedure...
0
9656
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9498
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
10172
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
10110
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
8993
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7517
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
6750
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
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.