Re: Declare minimum PHP version required?

From: Date: Tue, 04 Feb 2014 18:30:46 +0000
Subject: Re: Declare minimum PHP version required?
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-72206@lists.php.net to get a copy of this message
Hi Yasuo, I don't think PHP needs new language constructs for assertions. Actually, the code from your example may be implemented as two calls to assert(). assert(extension_loaded('foo'), 'You need foo module'); assert(extension_loaded('bar'), 'You need bar module'); I think it's much clear then inventing new syntax. With Joe's proposal these asserts might be completely eliminated. And it's backward and forward compatible :) BTW: I didn't follow all the discussion, so I may miss some points. Thanks. Dmitry. On Tue, Feb 4, 2014 at 1:08 PM, Yasuo Ohgaki <yohgaki@ohgaki.net> wrote: > Hi all, > > On Mon, Feb 3, 2014 at 7:55 PM, Yasuo Ohgaki <yohgaki@ohgaki.net> wrote: > >> 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. >> > > Similar thing could be achieved with new assert() w/o any overheads. > > https://wiki.php.net/rfc/expectations > > assert('version_compare(PHP_VERSION, "5.5.0", ">=")', > 'You need PHP 5.5.0 > or later'); > > Since assert() only accepts expression, it might be nice to have > > declare('assert') { > if (!extension_loaded('foo')) { > echo 'You need foo module'; > return FALSE; > } > if (!extension_loaded('bar')) { > echo 'You need bar module'; > return FALSE > } > return TRUE; > } > > Usual PHP code might be easier to write complex assertion. > It may be possible to share most of the new assertion code. > > Just an idea. > What do you think Dmitry? > > Regards, > > -- > Yasuo Ohgaki > yohgaki@ohgaki.net >

« previous php.internals (#72206) next »