Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:70592 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 50329 invoked from network); 11 Dec 2013 15:29:42 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Dec 2013 15:29:42 -0000 Authentication-Results: pb1.pair.com header.from=chobieee@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=chobieee@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.160.46 as permitted sender) X-PHP-List-Original-Sender: chobieee@gmail.com X-Host-Fingerprint: 209.85.160.46 mail-pb0-f46.google.com Received: from [209.85.160.46] ([209.85.160.46:42710] helo=mail-pb0-f46.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D2/63-22966-4E488A25 for ; Wed, 11 Dec 2013 10:29:41 -0500 Received: by mail-pb0-f46.google.com with SMTP id md12so10057633pbc.5 for ; Wed, 11 Dec 2013 07:29:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=pbRXbWGcas3HuwqXd1Rc0eysBuqXCA/FSak0bzniRR8=; b=jueNP4RBDb2TNwtSY0U+IoL9mZEzaFoneppEo5BHby+4v7nXF3Vwb/FQA1DF2cBS/K iTbHGg17HrSWcDux9Ai5EAorUX11qbw8oNpW8LJDPJJpXB9vFx/0g5nlyElz6Vpb0dvp oqKZRpLLUShKwxnfTy40A8w12HssE/noYzss3dLN3a9P6uddLezTY9zotM23FsXOzwLw U53U+3qlonkNs3rFWGpbqSdTNl22wmHcymzys+l7Vz20zc7giJ4gpVVDN68iYpSAFOQM fPn73KAUoDN5A3yD2YKNx2QPYelkQUk18HjZTbw74nwgMr77j2fVxF4XWJW709lJECd0 Gt/w== MIME-Version: 1.0 X-Received: by 10.66.146.199 with SMTP id te7mr2392771pab.106.1386775777825; Wed, 11 Dec 2013 07:29:37 -0800 (PST) Received: by 10.68.1.231 with HTTP; Wed, 11 Dec 2013 07:29:37 -0800 (PST) In-Reply-To: References: Date: Thu, 12 Dec 2013 00:29:37 +0900 Message-ID: To: Marco Pivetta Cc: PHP internals Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [PHP-DEV] Proposal: ArraySerializable interface From: chobieee@gmail.com (chobie) 2013/12/11 Marco Pivetta : > I am personally (currently) relying on the approach where array conversion > gives me the values of the various properties as objects (when they are > objects), so I wouldn't like another magic operator in there (to deal > with/workaround). > Wondering why this approach would be better than doing a recursive array map > iteration. > > Pardon my naive and inelegant way of dealing with maps (see the running > example at http://3v4l.org/ZOodL ): Yea, I also use same approach. let me explain my story: I'm working at web gaming company and maintain many models which are complex and nested classes.( like Player, Inventory, Item... ) Currently, We use `toArray` or whatever method when passing those variables to web browser. Issue with this approach: Developer have to consider returning values which handle recursively, removing unwanted values...etc. Also, Unfortunately this approach is company specific. We'd like to follow common way to cast array from object. The pros of proposed approach: * Easy to convert to array from complex object. returning value only contains primitive types (long, double, string, array). and call `__toArray` method recursively when the value contains object. I think this rule will reduce production costs. just define __toArray method and wanted returning values. don't care about other things. > I'm actually wondering about the opposite case. > What would I have to do to have the previous behavior working on an `ArraySerializable` instance (basically ignore `__toArray()` for one particular cast)? > I don't want to go the reflection way :-) I'm curious about your story. What king of work do you do? This kind of proposes regards coding standards. It's okay to propose which part.