Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:94921 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 62286 invoked from network); 8 Aug 2016 12:46:07 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Aug 2016 12:46:07 -0000 Authentication-Results: pb1.pair.com header.from=marijic.silvio@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=marijic.silvio@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.223.172 as permitted sender) X-PHP-List-Original-Sender: marijic.silvio@gmail.com X-Host-Fingerprint: 209.85.223.172 mail-io0-f172.google.com Received: from [209.85.223.172] ([209.85.223.172:36521] helo=mail-io0-f172.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E2/3D-33134-D0F78A75 for ; Mon, 08 Aug 2016 08:46:05 -0400 Received: by mail-io0-f172.google.com with SMTP id b62so356152106iod.3 for ; Mon, 08 Aug 2016 05:46:05 -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; bh=qWk7rEYlJHB9+QOd9QcYsMbvWqmJvKdAIFhU0IFu5LM=; b=AtcH54x0wY+Jkch18aAlPWeRubGZIbRJ/TtJe8yQGDWdZqbh+n0hOQP3hvEMF+k//h dr/zImid8TmWIgiIVNeGihpAs9OxRFWh+vswPj59bpOlRg0qSKxqBEJu/y10OMqlOMN9 TdBWrxGWBhAy+3gh1sqsGn5pvjgjN34mWwGu2NWM1ZCVr7yv6fx+5mVyEg2EBipss6JU EKJbEyTKF2j6W/PTc0tbaVKhafR9DCU3vX3ncjjKVqCpUGKjmTB/UplrGL1+jyJySMkP AYsIpx765MsmNU/9lKxUfV8axqHMGYFDVECXKnkFLnUkQsY5DTTttORLseExQJQU/+kv 0/Eg== 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; bh=qWk7rEYlJHB9+QOd9QcYsMbvWqmJvKdAIFhU0IFu5LM=; b=C7cbEfM1oye/IgTOv/qOJX5agNp95+qdFu8n4uzodX4XsJ9h7FUYm6md9qTmRABzMK FlOxPN4U6dRSEiwYyoNI+DoIi4zSu9D+xGc4ADfK0eOxUbMDbo0j1fVEs6dc50s9D+eb DZl5SxRyguebSyd4MNFmGSxh1sVnZUuVobsgxtlfPIodf1gjZp/QUGmOFzZkEpJLJo2m ss0XPeLzooqN4xUpzjYs8l6kzHF0p0tyvAHVKjtpA3NZ4xpLuqsu6DzSUS3Y1eIu+G3n sU1elhoscmdj3/JWf6G/jVwAtE+6vm1hW3m2KR8rFUMzGaAz9l2hPKJc23FYAgfrrBQE JV7w== X-Gm-Message-State: AEkoouswaiLNcndgk5DJYlGO0OdxHvv89QQEQLelgO85Mj02pOxKq9dQ60Dmehf9HjBxGpHS27pjf9uI3jFq7A== X-Received: by 10.107.57.215 with SMTP id g206mr101654205ioa.194.1470660362271; Mon, 08 Aug 2016 05:46:02 -0700 (PDT) MIME-Version: 1.0 Received: by 10.36.239.133 with HTTP; Mon, 8 Aug 2016 05:46:01 -0700 (PDT) In-Reply-To: References: Date: Mon, 8 Aug 2016 14:46:01 +0200 Message-ID: To: =?UTF-8?Q?Micha=C5=82_Brzuchalski?= Cc: PHP Internals List Content-Type: multipart/alternative; boundary=001a114ab9c27a812e05398ecc9a Subject: Re: [PHP-DEV] RFC - Immutable classes From: marijic.silvio@gmail.com (=?UTF-8?Q?Silvio_Mariji=C4=87?=) --001a114ab9c27a812e05398ecc9a Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Btw, I was not aware that there was already conversation on immutable classes. 2016-08-08 14:31 GMT+02:00 Silvio Mariji=C4=87 : > I see your standpoint, but I think it could cause confusion because of > final classes. I think "immutable" is more suited here. > What I try to achieve is something similar like case classes in Scala. > > Best regards, > > 2016-08-08 13:16 GMT+02:00 Micha=C5=82 Brzuchalski : > >> Hi Silvio, >> >> Look into my talk about final properties https://marc.info/? >> t=3D145979255800003&r=3D1&w=3D2 maybe there would be something usefull. >> There is also talk about mutable and immutable properties and other clas= s >> modifiers also about var and val. >> I'm not sure that it should be class midifier rather than proprty >> modifier keyword. >> >> regards, >> -- >> Micha=C5=82 Brzuchalski >> >> 2016-08-08 12:31 GMT+02:00 Silvio Mariji=C4=87 : >> >>> Hi, >>> >>> I would need your help with one idea. I'm working on one RFC that I'm >>> would >>> like to submit. Idea is that after you initialize object eg. after >>> constructor returns, object would be locked, and you wouldn't be able t= o >>> change properties on that object anymore. It would like this: >>> >>> >> >>> immutable class Email { >>> > public $email; >>> > public function __construct($email){ >>> > $this->email =3D $email; >>> > } >>> > } >>> > $email =3D new Email("example@email.com"); >>> >>> >>> >>> After instance of class is created, object is "frozen" so call like thi= s >>> >>> $email->email =3D "new@email.com"; >>> >>> >>> Would result in error. >>> >>> I have already implementation up to certain degree, but I need one advi= ce >>> from more experienced developers. Where is the place where I could put >>> logic to lock object after the constructor has finished? Maybe in zend = vm >>> on ZEND_NEW token? >>> >>> Some constraints are needed: >>> >>> 1. Child class that extends immutable class must be defined as >>> immutable >>> also. >>> 2. If property on immutable class contains object, it must be instan= ce >>> of immutable class. >>> 3. You can not have immutability per property, it either whole class >>> or >>> none. >>> >>> Thank you all in advance. >>> >>> -- >>> Silvio Mariji=C4=87 >>> Software Engineer >>> 2e Systems >>> >> >> >> >> -- >> pozdrawiam >> -- >> Micha=C5=82 Brzuchalski >> > > > > -- > Silvio Mariji=C4=87 > Software Engineer > 2e Systems > --=20 Silvio Mariji=C4=87 Software Engineer 2e Systems --001a114ab9c27a812e05398ecc9a--