Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:3441 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 42292 invoked from network); 16 Jul 2003 10:00:46 -0000 Received: from unknown (HELO morpheus.webteckies.org) (24.132.35.224) by pb1.pair.com with SMTP; 16 Jul 2003 10:00:46 -0000 Received: from ghost.lan.webteckies.org (ghost.lan.webteckies.org [192.168.1.10]) by morpheus.webteckies.org (Postfix) with ESMTP id 4BEC5107C6; Wed, 16 Jul 2003 12:00:28 +0200 (CEST) Organization: Php.net To: Marcus =?iso-8859-15?q?B=F6rger?= Date: Wed, 16 Jul 2003 12:00:43 +0200 User-Agent: KMail/1.5.2 Cc: Php Dev References: <3F147B5D.5070406@chiaraquartet.net> <200307160127.52308.msopacua@php.net> <1422804488.20030716100114@post.rwth-aachen.de> In-Reply-To: <1422804488.20030716100114@post.rwth-aachen.de> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-15" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-ID: <200307161200.43568.msopacua@php.net> Subject: Re: [PHP-DEV] $this assignment and call_user_func question From: msopacua@php.net (Melvyn Sopacua) Hi again, On Wednesday 16 July 2003 10:01, Marcus B=F6rger 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 =3D 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 t= he > 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=20 illustrate the problem however, because the constructor for a string based= =20 DomDocument is the PHP_FUNCTION(xmldoc). Which means, the following does not work: class DomFromString extends DomDocument { function foo() { echo('foo'); } } $dom =3D new DomFromString($xml); var_dump($dom); This is because there are three *function* constructors, which do something= =20 usefull, which are returning the same object. I really don't see a way, to= =20 extend this object. The primary reason is: BC, missing methods, adding=20 convenience methods. Since PHP5 should also give a boost to PECL, I think there should be a way = to=20 extend a C-based class, somehow. I really don't favor the $this assignment = as=20 well, but what other option is there? Or is this specifick for the way the= =20 domxml module is setup, and people shouldn't write their classes like that? =2D- Melvyn