Solved

Reference to an object

Posted on 2000-02-17
5
164 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Router for PHP reqeusts 12 33
php mail headers 2 14
Wordpress syntax error 1 29
PHP code to retrieve NDFD weather forecasts. 6 38
Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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.

743 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

14 Experts available now in Live!

Get 1:1 Help Now