?
Solved

Reference to an object

Posted on 2000-02-17
5
Medium Priority
?
173 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

WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

770 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