Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:95648 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 63603 invoked from network); 5 Sep 2016 15:00:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Sep 2016 15:00:30 -0000 Received: from [127.0.0.1] ([127.0.0.1:5012]) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ECSTREAM id 22/50-45301-E888DC75 for ; Mon, 05 Sep 2016 11:00:30 -0400 Authentication-Results: pb1.pair.com header.from=tendoaki@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=tendoaki@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.174 as permitted sender) X-PHP-List-Original-Sender: tendoaki@gmail.com X-Host-Fingerprint: 209.85.217.174 mail-ua0-f174.google.com Received: from [209.85.217.174] ([209.85.217.174:33949] helo=mail-ua0-f174.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7C/9F-45301-85C7DC75 for ; Mon, 05 Sep 2016 10:08:26 -0400 Received: by mail-ua0-f174.google.com with SMTP id u68so7522516uau.1 for ; Mon, 05 Sep 2016 07:08:24 -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=M++8/wynTt/2oOvfjnKY+8yuMe/nV4iFft/rAeoof2A=; b=Hf44PTzbZet+l/MDJki5mYoGT9oCIjqIo8oel21H8m367T81Ml7FAX6p2A8X3S04bS mPTqA9xSMniYfHPFfO9IOPY9hZpepumbyEp4xWRXJD32j54+6RGqCg0YujXxyf+t3VPF 0OeyrdNwGDxnZcwhZEKmsqre1XCmmOBXX/d3DbR+KBOhNNyU+cCbygYOhgyy0upKpEys o02qjwEwglJObyD6OWq+EoAYlaK3UW76empXWqRfOHPJ/7jr3uG3xe4GqxshVkf3L5Xz 9bpCYdQ5dj1YxUpjpe79nIylS8UUlhou/YGYMn7qk8moQ6yql557kMfSNAarqEHrtQ43 ThWQ== 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=M++8/wynTt/2oOvfjnKY+8yuMe/nV4iFft/rAeoof2A=; b=fZvUSw7xLGG16r6mVYPZIILwirhnNOxAlTeT4nPS3qYIC22krdkEqRtb9bTKS8mLpZ 1sEv97BYp6iuav9bOhDrZ78zbZwf2vzb2jHJ8guOpQxJjjVxPhMkm9PVT5NVfss6xFBx VolSpqcdjjLvo8trwQXnuNh3udu1RdupfIg2XQOiO4QoWU/eE3AQF0+qBJcm+mnDBmXJ YZD91bqda6QkR0yONk/GuYfBw7SKyJgU98PE44RfYqqn63hATdraGPc+lQjRYwBj9J5W 2QyAuwkmSZgxQWfakvy1H3qhKzWhYTuCx+b8ex7NW/1Cfx9BzsgNJxU+p8nPa50F8WWW SEZg== X-Gm-Message-State: AE9vXwOvbCj4pU+Qe/zCKnO5rIkBhYZriERAOsGCMq4EXX7TN7NZN9KKgtizH2epXdzVEVa0ObnTtTAuTCrQMQ== X-Received: by 10.176.83.118 with SMTP id y51mr21295538uay.86.1473084501749; Mon, 05 Sep 2016 07:08:21 -0700 (PDT) MIME-Version: 1.0 Received: by 10.103.130.134 with HTTP; Mon, 5 Sep 2016 07:08:20 -0700 (PDT) In-Reply-To: References: Date: Mon, 5 Sep 2016 10:08:20 -0400 Message-ID: To: Davey Shafik Cc: Nicolas Grekas , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=94eb2c191fa07375ac053bc3361d Subject: Re: [PHP-DEV] Missing reflection info about strict types? From: tendoaki@gmail.com (Michael Morris) --94eb2c191fa07375ac053bc3361d Content-Type: text/plain; charset=UTF-8 On Mon, Sep 5, 2016 at 5:49 AM, Davey Shafik wrote: > > > On Sep 5, 2016, at 02:38, Nicolas Grekas > wrote: > > > > Hello, > > > > It looks like we miss a way to check by reflection if a function/method > has > > strict types enabled or not. > > > > We'd need to do this in Symfony to generate a file with concatenated > > classes, but split "declare_strict=1" classes out so that they don't > break > > (because there is no way to create a single file that contains both > strict > > and non-strict classes unfortunately also). > > > > Would it be possible to expose some flavor of ZEND_ACC_STRICT_TYPES to > > userland? > > Strict types are only enforced from the CALL site. A library author cannot > dictate that their code be called using strict types or not, only the file > actually calling the library methods can. Though, regardless, the type > hints do ensure that the value received is of the type specified, you just > won't know if it was coerced or not. > > Just like when you import a namespaced class and alias it, the alias only > works in the file the "use " statement is in. > > Therefore, you cannot actually author strict or non-strict classes period, > unless they are only called in the file in which they are defined. > Actually you can, in PHP 5 even. This sort of thing is what the assert() statement is for. public function stringsOnly( $var ) { assert(is_str($var), 'Strings Only!'); } This does have the weakness of not working when assertions are turned off. If $var is a form of user input then an exception test is called for, and likely should be done before stringsOnly in this example gets worked with. --94eb2c191fa07375ac053bc3361d--