Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125263 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 06B941A00BD for ; Mon, 26 Aug 2024 10:40:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1724668965; bh=mLoZvlMXXL1tXwOb/ViR3iYqI4YidP7YBrHjK1k4iHE=; h=Date:Subject:To:References:From:In-Reply-To:From; b=kFmwnzzzoItYbHVXYnuH9mGNfiDq2Vi0D+69Y/gmCqLsl7SAxbuYkGVijAHGqjKcN OjB+EhUiAC2eVXPtdrGqCtW78akYAab8OVjm+B/TbP0eOL5AnK+QBvPdZkgi3feqDX 4DCfsCkGyLoaehYJRho0JTR9vgOf64nCeV3+G7vUTkUOqa39haamx6HSwrLmdY57vx fkSgL8yTFctEWeJbqQgZ1Bmfmjo+FAgxAR4VdMCUwv8iWLcSvCKQhLzbuammgQY2zb ZLAbgMUPzkG7FWxyyAm2hmeGkC12sMB9UlFAgNtRWZSvuPYoeSMs5EGEE8Mc+b2jyQ Um8tXbguKFuHg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E7B1418003E for ; Mon, 26 Aug 2024 10:42:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DMARC_MISSING,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 26 Aug 2024 10:42:44 +0000 (UTC) Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-37198a6da58so2917779f8f.0 for ; Mon, 26 Aug 2024 03:40:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=scriptfusion-com.20230601.gappssmtp.com; s=20230601; t=1724668851; x=1725273651; darn=lists.php.net; h=in-reply-to:from:content-language:references:to:subject:user-agent :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to; bh=6Zpw/Aq+lQQYV9LGwAcrkSjhtlaB/+0ON3MODRWmt58=; b=O/o/EvELd/KS1D3NgcDVyHXxOHfr293/DCKLeWCiqlP10gfFRxp8O7Dgesnz5PHVUI hwmruNBIG/Ymmb6LrwxdLHSvWCbHmgMTcuT0BZNp8KoXK+1GKO0LFjQpNpVoNyU30aXO kUsZl9x0k2jh2zydLD1mtDaDv966mBo8ry+GAFUwRL7V6KkKr+unU6Et2npgjiLxpOQu 5b/y7ZX5TNDVBa91Fq9v22aJiy4ACD1lE2e4UHpgTyAM9P1urfLa3zWMnV2ra+3W4P9T sWbJCVdv1t6dgc5T0s4ifYQZxn1OxoZIJA3/9pSGaFRIorIK67qkpA+INUsWdIQc4+zY P4Zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724668851; x=1725273651; h=in-reply-to:from:content-language:references:to:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=6Zpw/Aq+lQQYV9LGwAcrkSjhtlaB/+0ON3MODRWmt58=; b=vDJx76/7apeYpTdweg1qXx/JcYN0lttkjFQZff/g/b9RZx1wKuKA3a1f5hoo4moZzG C8Dw85nwY7gei3IjGx4QcjGIoSUN1M1sykEPN+PAVV0Ref6kDwDwLLpKFyCRGkGjG7jB anOViC4n/Fo8scrrz5BXx5HW5dTsm7LhCVRZZQj1meMp8hT86yXVLgUn3OvELXtwJKjM yaiuKVA9Cfq+DMcdomr7y+H/VkycqQxjYXawy/gj9kbnRFSDjc+zbzekWFi8Hg0So95G tn++R09r3VK4Y6WWQJC7cSY7EKl6F5C5QbwgqGSKgZQ0xc8LpTW3X9HKIvLG0uKpNNYZ CHdQ== X-Gm-Message-State: AOJu0YypCM/iCJr+at3wIsyY/nZcecG+YNKH8mfu9ErVN/kaUXw3LpVq +SAYLR4QPmwiHdz0mEo2t2roBwO/leOsDwyzqPR+U//nGqq3UQshJmDy9JozB3q+rGCulKuf4qy 9 X-Google-Smtp-Source: AGHT+IHzfFa6PjgfSq+6ZnBwfbGMLdLgUoKzNWQcHe0xbqBrz/TgDMiA18+0MfQlfSrZ2yS66k8dKQ== X-Received: by 2002:a5d:4451:0:b0:371:88f6:7f98 with SMTP id ffacd0b85a97d-373118c83bdmr7099931f8f.38.1724668850505; Mon, 26 Aug 2024 03:40:50 -0700 (PDT) Received: from ?IPV6:2a01:4b00:bf09:5101:24c4:e0bf:99bf:8460? ([2a01:4b00:bf09:5101:24c4:e0bf:99bf:8460]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3730810fb33sm10375213f8f.13.2024.08.26.03.40.49 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 26 Aug 2024 03:40:50 -0700 (PDT) Content-Type: multipart/alternative; boundary="------------x00kA4jstlm03ThpQfpeudFj" Message-ID: Date: Mon, 26 Aug 2024 11:40:49 +0100 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] [RFC] Default expression To: internals@lists.php.net References: <792a811e-edf8-4a82-8422-e11cc302a6db@scriptfusion.com> <71F1A1D0-9958-4C86-B8C4-50B502B7560D@getmailspring.com> <99846F78-38F8-4549-B0A6-6310933AA78D@newclarity.net> <88BCC47D-C8FF-44DB-8816-17CB899CD887@rwec.co.uk> Content-Language: en-GB In-Reply-To: <88BCC47D-C8FF-44DB-8816-17CB899CD887@rwec.co.uk> From: bilge@scriptfusion.com (Bilge) This is a multi-part message in MIME format. --------------x00kA4jstlm03ThpQfpeudFj Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 26/08/2024 08:28, Rowan Tommins [IMSoP] wrote: > As far as I can see, nobody has actually justified reading values out in this way, only said it's a side-effect of the current implementation. It's pretty useful for testing. > Aside: one of those examples brings up an interesting question: is the value pulled out by "default" calculated only once, or each time it's mentioned? In other words, would this create 3 pointers to the same object, or 3 different objects? > > foo(array|Something $x=new Something); > foo([default, default, default]); Thanks for this interesting question. Here is the output from your (slightly modified) script: class Something {} function foo(array|Something $x=new Something) {return $x;} var_dump($x = foo([default, default, default])); var_dump($x[0] === $x[1]); array(3) {   [0]=>   object(Something)#1 (0) {   }   [1]=>   object(Something)#2 (0) {   }   [2]=>   object(Something)#3 (0) {   } } bool(false) As you can observe from the object hashes, each object is unique. That is, we fetch the default value each time the keyword appears, which in the case of objects, creates a new instance each time. I will update the RFC with this information. Cheers, Bilge --------------x00kA4jstlm03ThpQfpeudFj Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
On 26/08/2024 08:28, Rowan Tommins [IMSoP] wrote:
As far as I can see, nobody has actually justified reading values out in this way, only said it's a side-effect of the current implementation.
It's pretty useful for testing.
Aside: one of those examples brings up an interesting question: is the value pulled out by "default" calculated only once, or each time it's mentioned? In other words, would this create 3 pointers to the same object, or 3 different objects? 

foo(array|Something $x=new Something);
foo([default, default, default]);

Thanks for this interesting question. Here is the output from your (slightly modified) script:

class Something {}
function foo(array|Something $x=new Something) {return $x;}
var_dump($x = foo([default, default, default]));
var_dump($x[0] === $x[1]);

array(3) {
  [0]=>
  object(Something)#1 (0) {
  }
  [1]=>
  object(Something)#2 (0) {
  }
  [2]=>
  object(Something)#3 (0) {
  }
}
bool(false)

As you can observe from the object hashes, each object is unique. That is, we fetch the default value each time the keyword appears, which in the case of objects, creates a new instance each time. I will update the RFC with this information.

Cheers,
Bilge

--------------x00kA4jstlm03ThpQfpeudFj--