Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113985 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 82928 invoked from network); 7 Apr 2021 10:58:52 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 7 Apr 2021 10:58:52 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0D2D1180539 for ; Wed, 7 Apr 2021 03:58:08 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 7 Apr 2021 03:58:07 -0700 (PDT) Received: by mail-wm1-f45.google.com with SMTP id g18-20020a7bc4d20000b0290116042cfdd8so909779wmk.4 for ; Wed, 07 Apr 2021 03:58:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding:thread-index:content-language; bh=lyabigaqmZ9hM3+KtIlaqlqS1+iJ6bF+rLFRZ2Y0/po=; b=pi2I/afAxarkdi36SwbCgPSwCNIRxDXueqWkSNB0IfQvF0QX3c2YvZPpDVT7I16zFi uvf2NvgFtvM4xONwPBuuUszGCHBB4ntAG+wJEI05B0G14CpBBq/kd7AjOWyN1sSzo3IZ 4Q8zM3gE/UAyWBxTG7QE5MOyXAGgmD7UTxnkwLphu+w3FoNvOvVidVMnjuHDEF0u6b5Z +/Ud33SVzEmL19dSSpYTPABHkutYEI+nJ/3wlR7Zh8sn18SL4cXcoUy24NX1hJRO47+i NnmNcEktsOeNK8WFoBjdvSC0VejxwOidmKo0gQLgvhaecad10XhFIEDw83qMflAUMyJb rtXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding:thread-index:content-language; bh=lyabigaqmZ9hM3+KtIlaqlqS1+iJ6bF+rLFRZ2Y0/po=; b=bgimGrXCHKsl21coz0SfkTbMn/CiJeJPYcP6ns5wxWVOLkeDwsbXvL76ZMY/0fo7T1 7mN4g/KhkivB2qepARULPpq+WwH/qxsl1pJGg+dckbCAQfMM7MQNspN7MWiDRfX6cDYj 36qG6ORISL0iEVWSXn9wdRhR/h05GQ09eEIf/6yMhV+MSsNhYrxPsfU/uS5DamZ7Ptk2 bnNld4PuIweBgf4zJ+wkTfZBZQ4pzVqRgFAQVexnZ6U4CCbdeFmWRxF5KcvMM+nxXPcs 0nYTNOqOwGoIA1jGt0zWrQPu7dd4/k/7d5gItGlba+ijyonV7kiwid0VWLJXyGGLfcYl aM8g== X-Gm-Message-State: AOAM530jG2YD8Y4UwLRD9Wm5hFvAPSP3Z8NVaWGd8/fndihghT1o5qPl OjXjaJIZqwk2oTexAFI0zwd1Pe5ge4WSww== X-Google-Smtp-Source: ABdhPJxP5bu4R6uQcuszZF/V23j8dwWF2+ilPwhX123yE9Cgaxp7npeGaqptILLqTfekwfZV/r6i0w== X-Received: by 2002:a05:600c:3325:: with SMTP id q37mr2616096wmp.45.1617793084435; Wed, 07 Apr 2021 03:58:04 -0700 (PDT) Received: from DESKTOPQD1QNOQ (static-202-12-248-43.dnt.net.pk. [43.248.12.202]) by smtp.gmail.com with ESMTPSA id p18sm38025596wrs.68.2021.04.07.03.58.02 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Apr 2021 03:58:04 -0700 (PDT) To: Date: Wed, 7 Apr 2021 15:58:03 +0500 Message-ID: <007001d72b9c$e3b3e870$ab1bb950$@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdcrlUWf83Kv315YQC2wizcjbnrSQA== Content-Language: en-us Subject: Empower Callables with Function Signature Hints From: office.hamzaahmad@gmail.com ("Hamza Ahmad") Hello Internals, I want to request making possible to catch functions with wrong signature when passed as callable. In other words, when a function or a method is passed as callable value, PHP will first confirm whether the function is of the write callable type that the function being executed requires. It will help catch silent errors. Currently, PHP does following: 1. Confirms whether a callable is valid. 2. Passes the callable value to a function, and the execution starts. 3. If the passed function receives values which's type is different than function signature, PHP throws an error. 4. If passed function returns nothing, the variable that wanted a value from the passed function receives null. 5. As a result, the unexpected results emerge. To resolve this issue, I propose to introduce a mechanism that allows to hint callable signatures. To understand the spirit of this request, look at the similar functionality that Angel Script Project provides with. 1. One defines a function definition. 2. Use its name to hint the same signature. 3. The compiler alerts about the incorrect signature before passing this to a function. If I could do this in PHP, I would write like following: `funcdef preg_replace_callback_hint(array $matches) : string;` If I accidently pass a callable which's signature is different than desired function call, the error is caught earlier. This message does not suggests syntax; it only points to a problem and suggests a solution. Any volunteers that would love to come up with syntax and implement this? I am curious to see the feedback. Regards Hamza Ahmad