[thelist] PHP syntax problem

Andy Warwick andy.w at creed.co.uk
Tue Apr 16 19:04:01 CDT 2002


I've just been reading some PHP code and trying to understand it, and it's using
something I've never seen before:

    $customer = &new Customer();

rather than

    $customer = new Customer();

I've had a look around the web and php.net, and figured this means the object is
being created by reference, and I've got my head around how that works with
simple variables:

 $a = 5;

 echo $a;   ----------> returns "5"

 $b = &$a;

 $b = 10;

 echo $a;   ----------> returns "10"

But I can't for the life of me work out why the class is being called in that
way, and what benefits it creates. AFAICT it's something to do with copying
objects, saving memory and the $this variable, but I can't find an easy example
of why it's needed.

Anyone offer any help?

(offlist if this is considered too off topic...)

Andy W

<tip type="Business Cards" author="Andy Warwick">
Consider putting your photo on your business card.

Most people remember faces better than they do names, so they might just
remember your card and company that much easier.

If you've never met someone, and you are arranging to meet in a public place -
like a conference or on a trade stand - you can pop one in the post so they can
pick you out.

It's also nice to be able to visualise who you are speaking to over the phone if
you have never met, and adds a personal touch to your business.
</tip>



More information about the thelist mailing list