RE: [php-objects] Class names case sensitive?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



--- Christopher Hendry <chendry@nyc.rr.com> wrote:
> conn =& DB::connect('mysql://username:password@hostspec/database_name');
>          ^^^
> 
> Excuse my ignorance here, but I just have to ask.  What is the ampersand
> doing in the above?  

Look in the manual for information about references. Also if you look at the
code for the connect() method (in DB.php), you'll clearly see:

    function &connect($dsn, $options = false)  

And the returns from that method are objects. The '=&' makes the assignment by
reference instead of giving a copy of the object. 

> I understand the ampersand when passing variables, but
> not in class declarations.  I've had it throw errors from the PEAR library
> and I just take out the ampersand and it works fine...

That is weird. What version of PEAR::DB are you using? what version of PHP, and
of PEAR? (hint: 'pear list' will tell you all the installed packages, 'pear
list-upgrades' will list all the upgrades for the installed packages)

Sometimes '=&' can be easily ignored in favor of '=' for assignment for simple
ojbects, just when you are dealing with complex objects that can be relatively
long-lived, it could make a difference in your memory usage, etc.

The following code works OK for me:

require_once 'DB.php';
$c =& DB::connect('mysql://localhost/mysql');
print_r($c);

My local versions are (PHP 4.3.0 compiled from source):

$ pear list

Installed packages:
===================
+----------------+---------+--------+
| Package        | Version | State  |
| Archive_Tar    | 1.0     | stable |
| Auth_SASL      | 1.0.0   | stable |
| Console_Getopt | 1.0     | stable |
| DB             | 1.4b1   | beta   |
| HTTP           | 1.2     | stable |
| Mail           | 1.0.2   | stable |
| Net_SMTP       | 1.1.1   | stable |
| Net_Socket     | 1.0.1   | stable |
| PEAR           | 1.0.1   | stable |
| XML_Parser     | 1.0     | stable |
| XML_RPC        | 1.0.3   | stable |
+----------------+---------+--------+


> 
> Clarity on this would be appreciated.  Thanks.  C

Apart from the section on references in the PHP manual, IIRC there is at least
one article on that topic at Zend.com. Read those and look at the examples, so
things will be more clear.




=====
--- Jesus M. Castagnetto (jcastagnetto@yahoo.com)

Research:
 http://metallo.scripps.edu/
Personal: http://www.castagnetto.org/

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

------------------------ Yahoo! Groups Sponsor ---------------------~-->
Get 128 Bit SSL Encryption!
http://us.click.yahoo.com/LIgTpC/vN2EAA/xGHJAA/saFolB/TM
---------------------------------------------------------------------~->

Look here for Free PHP Classes of objects:
http://phpclasses.UpperDesign.com/
To unsubscribe from this group, send an email to:
php-objects-unsubscribe@egroups.com

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux