Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:96928 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 52735 invoked from network); 16 Nov 2016 15:38:50 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Nov 2016 15:38:50 -0000 Authentication-Results: pb1.pair.com header.from=david.proweb@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=david.proweb@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.45 as permitted sender) X-PHP-List-Original-Sender: david.proweb@gmail.com X-Host-Fingerprint: 209.85.214.45 mail-it0-f45.google.com Received: from [209.85.214.45] ([209.85.214.45:37661] helo=mail-it0-f45.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D3/E2-05303-98D7C285 for ; Wed, 16 Nov 2016 10:38:49 -0500 Received: by mail-it0-f45.google.com with SMTP id b123so58759035itb.0 for ; Wed, 16 Nov 2016 07:38:49 -0800 (PST) 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-transfer-encoding; bh=eV1GXyvDncFY6EZuEVl2gunZGqea8E1l+iYmB3sg6Wc=; b=07l3p1QT84v6JHESD6PC3Y9iaYigMbsoF/RWhq+hkWBiIafYyKnfMbU0rnETm9uwKr rQkhfPjDFOvifrWe9GhzPBPmkO0/D8SjA5g6sDkbLOci5Wg2grtdnfmOtKCDgRLsLseg klEyfapn08wg/g3fQ//goLrw752kDoUEfPkMRNCOE6nIuQQsgi08iU/DHfCXUs5dSczR k3s2y1AcEBNYjRP9SVGEAXfUIHmXl/P17vECVo1o06EyxW7Pou11/ntTK04KRAYtHy3S dlldqla8zclUafNcmQmIZgymGSdTzB2Z6gOx58Uqalz6cfBZ/Tp8RHea9S1ogDv9k7Eq Izqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=eV1GXyvDncFY6EZuEVl2gunZGqea8E1l+iYmB3sg6Wc=; b=AwHZrOUhFHA3sCEutSafvSQc31h5yMhxCuq2hVldOQANdO4TIKeg2aWYUP7aE+2vNu w+AcsCZ0oX8RpYPS2TaGkJSgA+68+nESJ1cfNs2pfnSCkg8KGP3AduP8IvXsRaB5jokE yd7FO1KNK/vfVBT1tLaeiLb2NG3PYNkFVBzheiiFL5VJ+qCUngYNoFMdC/YYe1zglU78 i7R50GtlYUkwJN8ZjLetftE+kt83nS8UrX9tAl/yZbHajiMh/h0VwjDFC8nvUvMPtnNI JGYodPYqvs9NBIcoHJY/KHbm+ZV9/sZrRUs48Y6lmyXli52ziGaTpV7Amh8DW/eSBslH 5BAw== X-Gm-Message-State: ABUngvdr+5GADuc1mIDPl3SPXLlxYhtV2YI/biNTNYcuUInBl2OrteLBcAsWMKmn2EQM0mftti9yYB4nNrLCnQ== X-Received: by 10.36.139.4 with SMTP id g4mr8275577ite.35.1479310695482; Wed, 16 Nov 2016 07:38:15 -0800 (PST) MIME-Version: 1.0 Received: by 10.107.142.148 with HTTP; Wed, 16 Nov 2016 07:37:55 -0800 (PST) In-Reply-To: References: Date: Wed, 16 Nov 2016 13:37:55 -0200 Message-ID: To: =?UTF-8?Q?Silvio_Mariji=C4=87?= Cc: PHP Internals List Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Immutability RFC From: david.proweb@gmail.com (David Rodrigues) 2016-11-16 11:57 GMT-02:00 Silvio Mariji=C4=87 : > If we treat those objects as values then this should return true. But the= n > again there might be some confusion because then two operators are doing > the same thing. Maybe throw an error ? Suggestions ? I just thinking about "how it will be done"? I imagine that we should store all calling to memory, then I see two problems for this case: 1. High memory consumption: all immutable objects should be stored on memory eternally (or until the script ends). I mean: if I call it a hundred times with differents parameters, I'll have a hundred of used memory, that will avoid any used variables of be GC (once that it should stores it for references). 2. High CPU consumption: every time that I instantiate an immutable class, the engine will loop on each possibilities and check if all parameters match to then return the same object (or then, create a new). Then the major question for it is: should all parameters of an immutable constructor be considered on instantiate? Should I pass the exactly copy (read "reference") of object to the parameter to return the same instance or a "shallow copy"? For both problems above, I guess that a "factory pattern with cache" should works better, once that I could consider the exact value where it requires to be immutable, and I could cache only if it is really required, for instance: class SomeFactory { private static $cache =3D []; public static function getType(Type $type) { if (!$type->shouldBeCache()) { // Code flexibility... return new self($type); } if (!array_key_exists($type->id, self::$cache) { self::$cache[$type->id] =3D new self($type); } return self::$cache[$type->id]; } } --=20 David Rodrigues