Solved

Reference to an object

Posted on 2000-02-17
5
165 Views
Last Modified: 2006-11-17
Hi!

I want to have a reference to an object, but PHP3 creates allways a copy of the object:

<html>
<body>
<?php

function cref(&$o)
{
  return $o;
}

class test
{
  var $t;      
}

$t1=new test;
$t1->t=10;

$t2=$t1;
$t2->t=20;

echo $t1->t;  // out: 10 not 20

$t2=cref($t1);
$t2->t=20;

echo $t1->t;  // out: 10 not 20

$t2="t1";
$t3=$$t2;
$t3->t=20;

echo $t1->t;  // out: 10 not 20


?>
</body>
</html>
0
Comment
Question by:sven99
5 Comments
 

Expert Comment

by:roupik
ID: 2531394
change
$t3=$$t2; to $$t2->t=20;

and what about $t2=$t1->this; ?
0
 
LVL 1

Accepted Solution

by:
aikon earned 200 total points
ID: 2531526
Hi Sven99,

Sorry but I think you can do that with PHP3.

If you want reffer a variable you'll might use PHP4.

Regards.

0
 
LVL 2

Expert Comment

by:maxkir
ID: 2531532
Your only way to get a reference:
class test
{
    var $t;
}
function tt( $var)
{
   $var->t = 10;
}

$t1 = new test;
$t1->t = 20;
tt(&$t1);  
print $t1->t;  // should print 10;

0
 
LVL 2

Expert Comment

by:maxkir
ID: 2561518
sven99, any feedback ? Tell us something ;-)
0
 

Expert Comment

by:mrvithan
ID: 2622901
I think you cann't use pointer in PHP3
at page 66 of PHP manual. Please take a look
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now