Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121589 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 50590 invoked from network); 5 Nov 2023 13:37:35 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 5 Nov 2023 13:37:35 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id CDBD8180087 for ; Sun, 5 Nov 2023 05:37:34 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-vk1-f169.google.com (mail-vk1-f169.google.com [209.85.221.169]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 5 Nov 2023 05:37:34 -0800 (PST) Received: by mail-vk1-f169.google.com with SMTP id 71dfb90a1353d-4abf86c5ae1so786486e0c.3 for ; Sun, 05 Nov 2023 05:37:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699191453; x=1699796253; darn=lists.php.net; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=RUw0dpx0W+IttkrIDn7ArmCURHh33XQU3SapFtz0VL8=; b=J/msfl+Y5mk+LH5gmEP+aJ/0P+BcBiardGXn5DM41+Jl6wbZB38NiZDMDvzX95fmlq kbpEwlos0DLygi3QXNUngWelFZS3EWG5Qaurzn97dFn6t4dIqlMnx72fN7lQTZr4PvqC rIxLbdFM6xmF7zbwkW8fZNoRv7aZdJYbR3KJxQXEBSx12jom746+OtP3M50II6oMkcfo ickPRc4ShpENg0JbWIPjobRJEs0zQsGcY7R6iDHs4kq4u6wEF6e94DVskvRv/Ic9KMGP OlYB2F//c9CoHnzIhy7/lq9sntto0TG6HdTphIybf3m59MJAG5joWbVKVefCEDRFWFBp diTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699191453; x=1699796253; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=RUw0dpx0W+IttkrIDn7ArmCURHh33XQU3SapFtz0VL8=; b=Hxj0Jwr7TxsxUySYiTm/X7HGFVq34FQAru4yRXrcNHoeQ0wOhLqP2qjW9Z5CoMwL1n 950sAwWE51dZXHW5zwBEC+a732y2KiPrtHikH1BiyCNyMPfRrZuvMK9AObvgEleOnv+3 thwdzsg3Yl2aMnGdLGniToKzbEKG22oYnWqHtg/nC4wZLF76OwhCy88PF1uVDZNBNN60 9jeVNQ7bnKbpFzVTz/7zSHcncozkGnHB6BlRCoLu7aBqNgoRzugR+KWtTRjrzTzL8FD2 HJWN2mDGn1ywvhxoyvoEJemupO9nTLVZAswL7Y297tBhwvCtKazy2SCecpp5zIkkjSTZ nRXA== X-Gm-Message-State: AOJu0YzKPqflIQdMZIovAyYdb0GBVxAGsq1qaWo34FF4za/XTKq6C7gK 3OVyDozBNiLHxuObA+kQy0pT55mg+1tavYCUekICRZ2XKzsQQg== X-Google-Smtp-Source: AGHT+IG8zK6Fk53j08O+hkKzeozJ3hzP+OouYQzfep9HK5AIp+RZXVMdsMLafaQH226T01Y5hzo31rpRUXPW6vLIzlE= X-Received: by 2002:a1f:a6d6:0:b0:4a8:a289:41ea with SMTP id p205-20020a1fa6d6000000b004a8a28941eamr22879479vke.14.1699191452975; Sun, 05 Nov 2023 05:37:32 -0800 (PST) MIME-Version: 1.0 Date: Sun, 5 Nov 2023 14:37:20 +0100 Message-ID: To: php internals Content-Type: multipart/alternative; boundary="000000000000f5caf1060967d669" Subject: [Discussion] Variable Type Declaration Before Usage From: oladoyinbov@gmail.com (Oladoyinbo Vincent) --000000000000f5caf1060967d669 Content-Type: text/plain; charset="UTF-8" Hello Internals, I was wondering if php could introduce this feature or if any experienced C dev here can work on the implementation of this feature. Local based variable declaration before usage is available in most languages like javascript, python, and many more. php has this, but it's only available while working/dealing with oop related. There is already an RFC on this: https://wiki.php.net/rfc/local_variable_types, but it doesn't propose a good usage syntax to promote readability. Well, i figured out how this feature syntax could look like: ``` $info: string; $price: float; $number: int = 125; $run: \Closure = fn( string $str ) => $str; echo $number; // 125 $info = $number; // TypeError $price = $number; // TypeError $number = 12.5; // TypeError $run = "hello world"; // TypeError ``` I was kind of thinking if the declared variables may also affect functions params: ```php function priceInfo($price, $info) { return $info . ': $ ' . $price; } echo priceInfo(12, 2); // TypeError echo priceInfo(12.5, 'Price:'); // Price: $12.5 ``` So, what is your opinion on this? Best Regards, Oladoyinbo Vincent. --000000000000f5caf1060967d669--