Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:63400 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 44981 invoked from network); 14 Oct 2012 08:43:39 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Oct 2012 08:43:39 -0000 Authentication-Results: pb1.pair.com smtp.mail=bschussek@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=bschussek@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.160.170 as permitted sender) X-PHP-List-Original-Sender: bschussek@gmail.com X-Host-Fingerprint: 209.85.160.170 mail-gh0-f170.google.com Received: from [209.85.160.170] ([209.85.160.170:64989] helo=mail-gh0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 19/04-11197-A3B7A705 for ; Sun, 14 Oct 2012 04:43:38 -0400 Received: by mail-gh0-f170.google.com with SMTP id g14so1290523ghb.29 for ; Sun, 14 Oct 2012 01:43:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=HcChyp5q8XcoP/FPhnyJofQNrMa14569FlIZJl7w8NU=; b=zg+mmOj1flvcl127w4qeZoUslb3X8CXuwxUjdVr1UUiM/ExL3qhMDqZ7B8U0ZDyh18 TmKo47lcScWLMyN5+KpaedWNKKH2MZn9PuUg14ctMiRCHYSx7QhEaHQQ2+QfTqM6XlA3 wuLgcOPJjSqDimpR2SQWwiZVlWmlg1kdVVw65XLG4ZcUyXKNEztp1NWty50oJUrVQzHJ ISXPxB5WuLz1D69e6jxGIktmtSQNKftpC72pzV7ZvX06Drb6R71w2GB3qsFg8qs4gfJG vYrZMcd8z0UsS/Q4m1f3r0C04iyqCaB89rDS3G6rbxp/Q9cKef7s1z5ffbL4LY7Wc6gP 5clw== Received: by 10.101.74.13 with SMTP id b13mr2470108anl.78.1350204215057; Sun, 14 Oct 2012 01:43:35 -0700 (PDT) MIME-Version: 1.0 Received: by 10.101.17.19 with HTTP; Sun, 14 Oct 2012 01:43:04 -0700 (PDT) In-Reply-To: <9570D903A3BECE4092E924C2985CE485612B578E@MBX202.domain.local> References: <9570D903A3BECE4092E924C2985CE485612B53E4@MBX202.domain.local> <9570D903A3BECE4092E924C2985CE485612B578E@MBX202.domain.local> Date: Sun, 14 Oct 2012 10:43:04 +0200 Message-ID: To: Clint Priest Cc: "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] [PHP-DEV [RFC] Property Accessors v1.2 From: bschussek@gmail.com (Bernhard Schussek) Hi Clint, 1) Point taken. 2) The use case can be solved with an object implementing ArrayAccess, but not pragmatically, because then you need a class for *each* bidirectional association. Let me give a short example: Given the class Article with a bidirectional many-to-one relation to Category and a bidirectional many-to-many relation to Tag, currently you implement the following methods to manage these relations: Article::setCategory($category); Article::addTag($tag); Category::addArticle($article); // calls $article->setCategory($category) Tag::addArticle($article); // calls $article->addTag($tag) (there are different ways to implement this, but usually at least one side of the relation also calls the setter/adder on the other side) You *cannot* implement the $articles collection in Category and Tag using the same class ArticleCollection, because in one case addArticle($article) calls setCategory($category), in the other addTag($tag). In other words, ArticleCollection depends both on the related class (Category, Tag) and the arity (setXxx() vs. addXxx()) of the relation. Consequently, every relation needs a custom collection class and you end up with the classes Article Category Tag ArticleTags CategoryArticles TagArticles just for this simple example if following your approach. With array accessors, this can be solved much more elegantly: class Article { public $category { set(); get(); } public $tags { offsetSet(); offsetGet(); } } class Category { public $articles { offsetSet($offset, $article) { $this->_articles[$offset] = $article; $article->category = $this; } offsetGet(); } } class Tag { public $articles { offsetSet($offset, $article) { $this->_articles[$offset] = $article; $article->tags[] = $this; } offsetGet(); } } $article->category = $category; $article->tags[] = $tag; $category->articles[] = $article; // sets $article->category = $category $tag->articles[] = $article; // adds $article->tags[] = $tag (I know that this example has some flaws, like the automatic offsetGet() or the missing $_articles field, but I guess you get my point) 3) I don't know if many other languages allow overloading of the array accessors at all. Cheers, Bernhard