Re: [PHP-DEV] [RFC] Implicit isset() in Shorthand Ternary Operator

2014-09-18 Thread Pete Boere
I'm seeing '??' as analogous to the way JS developers use '||', and I use
that all the time when writing JS.

Personally I wouldn't be interested in a function version because the
short-circuiting of '??' is an important distinction; not something you can
replicate with a function. Therefore having both would be confusing IMO.

Also, not much sure about a '??=', perhaps it should be a followup RFC
should '??' be accepted.



On 18 September 2014 10:26, Gwynne Raskind  wrote:

> On Sep 17, 2014, at 11:40, Matthew Fonda  wrote:
> > Hi Andrea,
> >
> > This is great -- thanks to you and Nikita for the work here.
> >
> > Syntax wise, I would prefer a function-like syntax, e.g. coalesce($a, $b,
> > 'c') or ifsetor() instead of $a ?? $b ?? 'c'. I find this more readable,
> > and it avoids any possible confusion about precedence within the
> > expressions. Either way, still +1 for this feature.
> >
> > Best regards,
> > --Matthew
>
> I’m STRONGLY +1 in favor of this operator, ASAP; I’ve had to write more
> than a few hacks to keep a large codebase I’m responsible from being a
> complete mess of isset() checks - 5.6 has saved me a lot of what used to be
> ugly workarounds (variadic functions anyone?), but this one still haunts me.
>
> I would argue for both coalesce() (as a language token) and ?? and ??=, as
> shorthand forms, giving the user a choice as to which they find more
> readable. ?? is standard in both .NET and Apple’s Swift language - Apple
> added it to Swift (including the chaining behavior) early during the beta
> cycle due to user demand for exactly this kind of logic, and it’s been part
> of C# for a long time.
>
> -- Gwynne Raskind
>
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Pete Boere
Web Developer


Re: [PHP-DEV] RFC: alternative callback syntax

2012-09-20 Thread Pete Boere
Tentative +1 for the func_name::callable version.

callable seems more generic, and possibly more intuitive when scan reading
code that contains lots of 'function'.

class A {
static function init() {
$inst = new self;
var_export <http://www.php.net/var_export>($inst->bar::callable);
$inst->bar();
}
function bar() {
var_export <http://www.php.net/var_export>(B::baz::callable);
}}





-- 
Pete Boere
Web Developer


[PHP-DEV] __init magic method

2013-01-22 Thread Pete Boere
Has there ever been any discussion on an __init magic method for
bootstraping static properties on class load?

The usual solution I come up with is manually calling an init method post
class definition, which works, though I'd call it slighly less than elegant:

class Foo {
static $bar;
static function init () {
// Create $bar with expressions...
self::$bar = $bar;
}
}
Foo:init();

A custom autoloader could of course anticipate this but with systems like
composer that have a shared autoload, it'd be nicer to use those than rely
on a custom loader.


-- 
Pete Boere
Web Developer


Re: [PHP-DEV] __init magic method

2013-01-22 Thread Pete Boere
>
> What's your use case for this kind of static properties? What if you make
> them private/protected and use an accessor method to initialize them (and
> avoid the overhead during autoloading)?
>

It's the overhead of repeatedly calling an accessor method which I'd prefer
to avoid.


-- 
Pete Boere
Web Developer