Re: Extending a class with a static constructur (like PEAR::DB)

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

 



weston@xxxxxxxxxxxxxxx wrote:
Weston wrote:


$dte = DBToyExt::connect("mysql://weston_tssa:******@localhost/weston_tssa");

$dte->testext('testing');
$dte->testext($dte->moo);
$dte->testext($dte->bar);
>>>
$dte will only have the return value of DBToyExt::connect() - it won't
allow you to access other methods in the class.

You'll need to:

$dbtoy = new DBToyExt();
$dbtoy->connect(....)
$dbtoy->testext('testing');


Thanks! Works like a charm:

http://weston.canncentral.org/web_lab/mlib/DBToyExt2.php

That's interesting. I think I just sortof expected that since the canonical
invocation is through a statically called method, calling it by dereferencing
a specific object wouldn't work.

In your example, $dte holds whatever DBToyExt::connect returns (whether that's a connection resource, a boolean, a string - doesn't matter).

It's the same as:

function connect() {
  return true;
}

$x = connect();

$x will only hold what 'connect' returns.


If you do:

var_dump($dte);

It won't be an object, so you can't use that to reference other methods in that (or the parent) class(es).

--
Postgresql & php tutorials
http://www.designmagick.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux