Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:72246 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 54744 invoked from network); 5 Feb 2014 07:45:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Feb 2014 07:45:25 -0000 Authentication-Results: pb1.pair.com header.from=yohgaki@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=yohgaki@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.43 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 209.85.215.43 mail-la0-f43.google.com Received: from [209.85.215.43] ([209.85.215.43:42623] helo=mail-la0-f43.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 25/F2-22810-41CE1F25 for ; Wed, 05 Feb 2014 02:45:25 -0500 Received: by mail-la0-f43.google.com with SMTP id pv20so22410lab.16 for ; Tue, 04 Feb 2014 23:45:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=zXVEcGo5RJ5fLVIeb8ga1sFD5JxuTNafyGuR66yUVH4=; b=Z1uAO/42ZNofNNh/EfjSps6VbfawPGg6u8KZ3ZbMYUU5+LrRRIHtAxNV5z5HymQbLH lD29iYjdRfkgBhz/qllLawJSD5UNXnMso+qoGKbKgzKp6PVxYwS98ts6Yq6DvnYZDk9K YRUDsplzTDCiF6QQ6CAinvlayKN2wr146JsweNpKvhwY0Nmq74eOo+EYKXDaTgNpgY8v 75bpYSz/F9JNF75YSQFeqnydBJn0H3F8b9DHQoVOnd1ox5+ciVHB/TzxBmg4f/FqziRp sRO0Ttolja8bQ3PMLLHUuhCahSgc8BsSzVi0lRT02nWhmSxHP05a2hES5YrshCKywjKl +99Q== X-Received: by 10.112.202.105 with SMTP id kh9mr75409lbc.89.1391586321214; Tue, 04 Feb 2014 23:45:21 -0800 (PST) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.112.199.37 with HTTP; Tue, 4 Feb 2014 23:44:41 -0800 (PST) In-Reply-To: <52F1E58F.3050105@sugarcrm.com> References: <52EE2B66.4040005@pthreads.org> <52F157BE.3020804@ajf.me> <52F15FD6.7060901@ajf.me> <52F1E58F.3050105@sugarcrm.com> Date: Wed, 5 Feb 2014 16:44:41 +0900 X-Google-Sender-Auth: Y541SJH9lOo87Bf-7Jgd2FVTVCQ Message-ID: To: Stas Malyshev Cc: PHP internals Content-Type: multipart/alternative; boundary=001a11c36c9459b0c404f1a3f0b6 Subject: Re: [PHP-DEV] RE: RFC: expectations/assertions From: yohgaki@ohgaki.net (Yasuo Ohgaki) --001a11c36c9459b0c404f1a3f0b6 Content-Type: text/plain; charset=UTF-8 Hi all, On Wed, Feb 5, 2014 at 4:17 PM, Stas Malyshev wrote: > >> php > assert('function() {return FALSE;}'); > >> php > assert('function() {return TRUE;}'); > > This runs function() code, which produces a closure. The closure is not > false, so assert is not fired. > > >> php > assert(eval('function() {return FALSE;};')); > > The eval here returns NULL (http://3v4l.org/cPpgj) so of course assert > will be fired here. From eval's manual: > eval() returns NULL unless return is called in the evaluated code, in > which case the value passed to return is returned. > Compare: > http://3v4l.org/vhe1p > http://3v4l.org/B79r3 Thank you. It looks I did wrong on my little experiment. > >> Warning: assert(): Assertion failed in php shell code on line 1 > >> > >> so closure in eval() works. I don't see reason not to allow closure > > Did you try: > assert(eval('function() {return TRUE;};')); > > Testing hypothesis usually involves not only testing something that > confirms it, but also something that may refute it. Otherwise you're not > really testing, you are just convincing yourself. > > > Added this to inconsistent behaviors RFC to track. > > > > https://wiki.php.net/rfc/inconsistent-behaviors#assert > > There's no inconsistent behaviors here and IMHO this RFC is turning into > "things people misunderstand in PHP". Maybe it should be moved to a blog > or some other space, because it by now has very little to do with what > RFCs are for. function func() {} assert(func()); and assert(function func() {}); would be better to get the same result. Besides, rather than $f = function func() {}; assert($f()); This form assert(function func() { // some code here }); is more user friendly and looks more modern language. I'm sure most users are used to latter form, since this form is used extensively in JavaScript. It keeps variable scope clean, too. I hope new assert() supports direct closure call :) Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net --001a11c36c9459b0c404f1a3f0b6--