Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:72102 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 5344 invoked from network); 3 Feb 2014 19:28:26 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Feb 2014 19:28:26 -0000 Authentication-Results: pb1.pair.com smtp.mail=yohgaki@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=yohgaki@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.177 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 209.85.217.177 mail-lb0-f177.google.com Received: from [209.85.217.177] ([209.85.217.177:46201] helo=mail-lb0-f177.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7E/3C-35654-9DDEFE25 for ; Mon, 03 Feb 2014 14:28:26 -0500 Received: by mail-lb0-f177.google.com with SMTP id z5so5551015lbh.8 for ; Mon, 03 Feb 2014 11:28:22 -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=Ag2gH4bZJXXWy0nwzPPs89adwvjPjz1b/XT1DkbG6rc=; b=mN/TTWAygGniLrPHHUVrCDb64S+wOCoVRqFWf0INjVlnrlJlLCZrpEkfSLSpAi0Woh u4N31Dyq3NrILADbd7hU2I7+9r51ApZ79KKlmVryqZopjUohMXhaQqtJEZP9imWo1tLi 67QTZLEKukGAe2rTTjGuhgY4cWB63D7iVTZY9UjbhxjgQ3V6a4/xSxdPBiwVcQynsnN/ Tne3SwyvjUx6bcjTzEXKj1Z4a++xTFiIta89Zs1F45qR95+CjEGxO8UR9ITHyx3uyQvp BIi7Z1BKWEfiOlxXYyB/fSxLo2Z5gdk5vkdMn7+vthrwytmLAyaaZ7CgfNG7AQoEjM+7 LWEg== X-Received: by 10.152.181.3 with SMTP id ds3mr9004lac.33.1391455702580; Mon, 03 Feb 2014 11:28:22 -0800 (PST) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.112.199.37 with HTTP; Mon, 3 Feb 2014 11:27:42 -0800 (PST) In-Reply-To: <52EF7ADA.8090001@lsces.co.uk> References: <52EF4BF8.60005@sugarcrm.com> <52EF7ADA.8090001@lsces.co.uk> Date: Tue, 4 Feb 2014 04:27:42 +0900 X-Google-Sender-Auth: zcTq5KZRBbybNpCYIzWOmeT98aA Message-ID: To: Lester Caine Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001a11c26f14df83ae04f1858698 Subject: Re: [PHP-DEV] Declare minimum PHP version required? From: yohgaki@ohgaki.net (Yasuo Ohgaki) --001a11c26f14df83ae04f1858698 Content-Type: text/plain; charset=UTF-8 Hi Lester, On Mon, Feb 3, 2014 at 8:17 PM, Lester Caine wrote: > Yasuo Ohgaki wrote: > >> > >The same thing can be done by version_compare() and die(), but it does >>>> >>> >not >>> >>>> > >make much sense executing script only to check PHP version and die, >>>> > >especially for libraries. For library, it is preferred to fail when >>>> it is >>>> >>> > >>> >Why not? That's what PHP does - executing scripts. >>> > >>> >>>> > >included, not when it is executed. I wouldn't write >>>> version_compare() and >>>> >>> > >>> >I don't understand - what is the difference? In PHP including and >>> >executing is the same thing. >>> > >>> >I think version_compare works just fine. >>> >> >> I works, but it requires CPU time for it and evaluation is delayed at >> run time, not compile time. Isn't it nice to know requirement is not met? >> >> We may extend declare() more. For example, loaded extensions. >> >> declare(module='pgsql,openssl'); >> >> With this, we could eliminate code like >> >> if (!extension_loaded('foo')) { >> die('You need foo module'); >> } >> if (!extension_loaded('bar')) { >> die('You need bar module'); >> } >> >> With opcache loaded extension check may be completely skipped. >> >> Evaluation at compile time and run time differs. >> > > I don't see how one can eliminate checking if a module is available. I do > not load MySQL on my systems so if someone tries to run a script requiring > MySQL they need a warning that it's not available. The build of PHP running > ensures that the available built in modules are of the right version, but > it's the third party libraries that I need to ensure are compatible with > the version of PHP I'm trying to run, and that the necessary extensions for > that library are loaded. Stuff updated to PHP5.5 may not work on the > systems that are still running PHP5.4 for compatibility reasons declare() is evaluated at compile time. It's not a usual function, but a Zend engine directive. Therefore, it can be used for declare(encoding='SJIS') which declare to compiler used encoding. Since it is evaluated at compile time, run time check is not needed at all when byte code cache is used. There are many code out there checks if (!extention_loaded(foo')) die('You need foo'). This is waste of CPU resources once it is checked. These requirements for scripts may be evaluated at compile time and script runs a little faster. Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net --001a11c26f14df83ae04f1858698--