Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125237 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 D245B1A00EA for ; Sun, 25 Aug 2024 20:32:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1724618044; bh=vMf9AfSi4leup1dDGiW+Ir9W6XEYShiGFDqCoYpwlnA=; h=Date:From:To:Cc:In-Reply-To:References:Subject:From; b=O113Hz8gDz121C+cxkZpQQbdFszQ3RcsRNKiJheL4MJi7SITrVQ5txwbO07144JNW q0dOAw12P6g1/A2u5jOZu4YLUctNzjJZL9T4xAhcEHxPf/C6SHrC/mB62KeFeGuurf M1P6/DQfQePrq8QGAFypNXYYaLa6NE2UByRDZXfQvH2hvcvxyQU09U90/h2ij/GulC H3ZgZRIXTXQXGAogCQDhboRXKHGuD4zec6AAB1yHOJCaAeQJHCkDb0wRCbzwjuDFA3 jP9iMto63cynhfwmBWFEUEQ7YlFBgfUkGmA7S3xvMs47uRrf+/CHKQczYZynNr4YQc elgHXAxnZDSbA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0A64C1801DA for ; Sun, 25 Aug 2024 20:34:02 +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=4.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DMARC_MISSING,HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,RCVD_IN_SBL_CSS,SPF_HELO_NONE, SPF_NONE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-yb1-f181.google.com (mail-yb1-f181.google.com [209.85.219.181]) (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 ; Sun, 25 Aug 2024 20:33:59 +0000 (UTC) Received: by mail-yb1-f181.google.com with SMTP id 3f1490d57ef6-e13c2ef0f6fso3545832276.3 for ; Sun, 25 Aug 2024 13:32:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=coggenterprises-com.20230601.gappssmtp.com; s=20230601; t=1724617926; x=1725222726; darn=lists.php.net; h=mime-version:subject:references:in-reply-to:message-id:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=vMf9AfSi4leup1dDGiW+Ir9W6XEYShiGFDqCoYpwlnA=; b=3KKPJLeXel8WSh1MZ+bnV/dKoO+Jvv4YlGZiSsHxNoYRrsVL918iLuNs/6K+zB9ExJ y+/CZBqushFL7ppORmbjgy/6SASJd5SOFoonaOozqhnC935l08FfRKYygXCXcoFKW9/C xb/OhgwzEmUdEfq6U3Ecwu+l+s8gVevOOjcS59VWOwav787p5S5+4+fNYRaao+XdrkOB 43OJcg1tclj7//eKJRGQbkbmXRX5OXNNFloG2DenFuFdZiSVkQxUzUKNTMMkqZMODn4c jqTBPbVGLkE041E3hQZThC9c50aL9G1GUMzktWVgjifZCt2v1xfQk0mBpISjZYHWFgXv vyMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724617926; x=1725222726; h=mime-version:subject:references:in-reply-to:message-id:cc:to:from :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=vMf9AfSi4leup1dDGiW+Ir9W6XEYShiGFDqCoYpwlnA=; b=Omh/Hd8BitMiTyEldpX0WBq2drvOAqOiY2Q8q4+qT3CIZKDTbPRWxxOHitj8ps728H X+VOHiCVHxDF6K1nFAt5mRSQWWwEBRqYN5QnjR6BYM5kDgLTjB9RZ+eDdrC20H2wYpzL UT09G2xt7CX5ictyFQVth/8Myh4RkTo1vbLbB190NZprxuSTJFcxDmqb8moA+Fo0btao vmjb3nQsFuA2vMs6Jn8JNM0Hwh86m6zLyrZQVSq7Y27IRRPNy1QMaMH+mx9ZS0FV0jzK 4zVCZ0riiyLrt5dBnlyzlLzuQkOubjXBQH43Ks0C41db2QGDmNDQ7BhAeXaA2E0jogQW tsQA== X-Gm-Message-State: AOJu0Yzr4Qh7F5v0W7NNR2qtkEosLiZoirjURfUsbyI72a3Eph6K3hJX nIx4mA/+Pe2ONPGvvj8b075sPnQEVd7CKyf56TdMY8krDYqQQta5CuDZ9dhEQxxSKurOVw/6bK5 g X-Google-Smtp-Source: AGHT+IE1QuAoNVAokkpvRFsrpJUVFEe78oAROSPmoeziyzszUeX4mCHoDazVoVWr972mQM5Fl7kqiA== X-Received: by 2002:a05:6902:2182:b0:e13:e8ee:d96f with SMTP id 3f1490d57ef6-e17a86639dfmr7745570276.35.1724617925998; Sun, 25 Aug 2024 13:32:05 -0700 (PDT) Received: from Johns-MacBook-Pro-2.local ([207.213.210.67]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e178e67d949sm1651466276.53.2024.08.25.13.32.05 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 25 Aug 2024 13:32:05 -0700 (PDT) Date: Sun, 25 Aug 2024 16:32:04 -0400 To: Bilge Cc: "=?utf-8?Q?internals=40lists.php.net?=" Message-ID: <62FBF4F4-7A83-4AD9-AA12-1F3DBB68805F@getmailspring.com> In-Reply-To: <6afeb23a-867f-457d-9b13-fdf5af02c31e@scriptfusion.com> References: <6afeb23a-867f-457d-9b13-fdf5af02c31e@scriptfusion.com> Subject: Re: [PHP-DEV] [RFC] Default expression X-Mailer: Mailspring Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="66cb94c4_19495cff_11f93" From: john@coggeshall.org (John Coggeshall) --66cb94c4_19495cff_11f93 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline > public function suspend(float|int|null $delay = null) { > parent::suspend((int)(($delay ?? 0) * 1000) ?: default); > } > } > > new MySuspension()->suspend(2.2345); // int(2234) > Not only have I demonstrated the need to use multiplication or division > to change the scale, but also the need to cast. > I appreciate what you're saying here. I've been struggling a little bit to really nail my language here on what I think should and shouldn't be allowed. Essentially I'm trying to say (and I think others are too) is this: The engine should not allow the use of default in an expression that doesn't ultimately evaluate to default *. In the above example the left - hand of the ?: operator doesn't use default , so it's evaluation is whatever it's evaluation is. The right-hand of the ?: operator DOES use default , and thus it must evaluate ultimately to default or that would be an error. Another example: parent::foo((default >= 10) ? default : 10) Would be permitted because the left-hand uses default , but the evaluation if the conditional where default was used for the true case true is default . Likewise the right-hand is just 10 and irrelevant This would not be permitted parent::foo((default >= 10) ? (default + 1) : 10) Because now the ultimate evaluation of default is default + 1 -- not default *The exception to the rule I've described above would be IFF the expression default is in only uses specific allowed operators like a subset of the bitwise operators. I very much appreciate that what is being described here is a significant effort to achieve, I'm not even sure it's reasonably possible.. but I just can't get behind the idea that (default)->foobar() is a valid expression in this context or a good idea for the language. The use of this proposed default keyword must have guardrails IMO. I think my definition above is a pretty reasonable attempt at capturing where I think the line is here and hopefully that helps guide this discussion. John --66cb94c4_19495cff_11f93 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline

    public function suspend(= float=7Cint=7Cnull =24delay =3D null) =7B
   &nb= sp;    parent::suspend((int)((=24delay =3F=3F 0) * 1000) =3F= : default);
    =7D
=7D

= new MySuspension()->suspend(2.2345); // int(2234)

Not on= ly have I demonstrated the need to use multiplication or division
to change the scale, but also the need to cast.


I appreciate what you're saying here.

I= 've been struggling a little bit to really nail my language here on what = I think should and shouldn't be allowed. Essentially I'm trying to say (a= nd I think others are too) is this:<= /span>

The engine should not allow the use of default=   in an expression that doesn't ultimately evaluate to = default *.

In the above example the left - hand= of the =3F: operator doesn't use default , so it's eva= luation is whatever it's evaluation is. The right-hand of the =3F: operat= or DOES use default , and thus it must evaluate ultimat= ely to default  or that would be an error. Another exam= ple:

parent::foo((default >=3D 10) =3F default : 1= 0) 

Would be permitted because the left-hand us= es default , but the evaluation if the conditional wher= e default  was used  for the true case true<= /code>  is default . Likewise the right-hand is ju= st 10 and irrelevant

This would not be permitted

<= div>parent::foo((default >=3D 10) =3F (default + 1) : 10)=

Because now the ultimate evaluation of default  is default + 1  -- not default&nbs= p;

*The exception to the rule I've described above would be= I=46=46 the expression default  is in only uses specif= ic allowed operators like a subset of the bitwise operators.

I very much appreciate that what is being described here is a significa= nt effort to achieve, I'm not even sure it's reasonably possible.. but I = just can't get behind the idea that (default)->foobar()&n= bsp; is a valid expression in this context or a good idea for the languag= e. The use of this proposed default  keyword must have = guardrails IMO. I think my definition above is a pretty reasonable attemp= t at capturing where I think the line is here and hopefully that helps gu= ide this discussion.
John



--66cb94c4_19495cff_11f93--