Solved

Reference to an object

Posted on 2000-02-17
5
170 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

740 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