TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 11-16-2008, 06:11 PM   #1 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default I was just thinking

Hi!

I was just thinking about something.

First of all, the codesnippets in this thread will be little messy cause I'm coding them here in the WYSIWYG(or w.e it's called).

Anyways, let's say you have here:

PHP Code:
class person
{

public 
$name;


THen you have this:

PHP Code:
class participants
{

public 
$person;

public function 
getName()
{
echo 
$person->name;
}


And this controller:
PHP Code:
include('participants.php');
include(
'person.php');

$person = new person();
$participants = new participants(); 
Then you want to set a variable inside participants with an object of the person, so you can use its function inside the class

PHP Code:
$participants->person $person
Then you edit the name of the person:

PHP Code:
$person->name 'Marcus'
If I then call the getName function:

PHP Code:
$participants->getName(); 
Will it echo out the name?


As I said, messy. But anyways, my question could probably be summed up in: If you set a variable inside class b, with an instance of class a, and then change a value of class a OUTSIDE of class b(for example in a controller); Will class b get that change? Or is it like when you assign the object to a variable inside class b, it copies class a AT THAT MOMENT, and every change you make to that object will not be in the variable in class b?

Fucked up question, but whatever, you get the point..
__________________
Tanax is offline  
Reply With Quote
Old 11-16-2008, 06:56 PM   #2 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

In short: yes, no.

Class instances are assigned by reference in PHP5 meaning that any changes, even after the assignment, are reflected wherever that instance is used. If you want to create a copy, use clone.
Salathe is offline  
Reply With Quote
The Following User Says Thank You to Salathe For This Useful Post:
codefreek (11-16-2008)
Old 11-16-2008, 11:06 PM   #3 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Ah I see.

Thank you!
__________________
Tanax is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 04:48 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design