Hi again,
On Wednesday 16 July 2003 10:01, Marcus B�rger wrote:
[ ... ]
> MS> I'm not farmiliar with the example Greg is getting at, but the
> following bit MS> me recently:
> MS> class DomFromString extends DomDocument
> MS> {
> MS> function DomFromString($string)
> MS> {
> MS> $this = domxml_open_mem($string);
> MS> }
> This should be a factory patter...static function ...return domxml_open...
Which returns a domxml object, without method 'foo'.
> MS> Note that the goal here, is to extend a class of which may not have the
> source MS> (or the time/ability to modify it) AND override it's
> constructor or the MS> constructor is provided by a function, rather than
> 'new' principle.
>
>
> You can of course overwrite the constructor in a derived class and all.
How would you know how to write the parents' constructor, if it's opaque?
If the constructor creates a resource, how would you mimmick this in PHP?
> So
> you are missing the possibility to exchange the contants of a dom clas,
> that's all you do this tricky stuff for?
The dom class is an example, but let's not focus on dom here. It does
illustrate the problem however, because the constructor for a string based
DomDocument is the PHP_FUNCTION(xmldoc).
Which means, the following does not work:
class DomFromString extends DomDocument
{
function foo()
{
echo('foo');
}
}
$dom = new DomFromString($xml);
var_dump($dom);
This is because there are three *function* constructors, which do something
usefull, which are returning the same object. I really don't see a way, to
extend this object. The primary reason is: BC, missing methods, adding
convenience methods.
Since PHP5 should also give a boost to PECL, I think there should be a way to
extend a C-based class, somehow. I really don't favor the $this assignment as
well, but what other option is there? Or is this specifick for the way the
domxml module is setup, and people shouldn't write their classes like that?
--
Melvyn
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php