Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 177
  • Last Modified:

Reference to an object

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
sven99
Asked:
sven99
1 Solution
 
roupikCommented:
change
$t3=$$t2; to $$t2->t=20;

and what about $t2=$t1->this; ?
0
 
aikonCommented:
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
 
maxkirCommented:
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
 
maxkirCommented:
sven99, any feedback ? Tell us something ;-)
0
 
mrvithanCommented:
I think you cann't use pointer in PHP3
at page 66 of PHP manual. Please take a look
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now