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

From: Date: Fri, 10 Mar 2006 00:05:36 +0000
Subject: Re: Extending a class with a static constructur (like PEAR::DB)
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-231743@lists.php.net to get a copy of this message
weston@leary.csoft.net 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/

« previous php.general (#231743) next »