Re: [PHP-DEV] Replacing array_slice

2018-07-16 Thread Jesse Schalken
On Tue, Jul 17, 2018 at 2:11 PM, Levi Morrison wrote: > And another: `$length` is a length when it's a positive number, but > it's an offset from the end when it's negative. > That's how substr() works, so it's at least consistent with that. It makes a lot more sense if you think of it as

Re: [PHP-DEV] Add is_vectorlike($array) function

2017-05-04 Thread Jesse Schalken
On Fri, May 5, 2017 at 8:18 AM, Rowan Collins wrote: > Maybe I'm misunderstanding what "with holes" means in this case, but I > would have expected any array with holes to trivially return false, here, > because we're looking for arrays with a complete set of consecutive

Re: [PHP-DEV] Add is_vectorlike($array) function

2017-05-04 Thread Jesse Schalken
On Tue, May 2, 2017 at 7:55 PM, Rowan Collins wrote: > +1, I've been thinking of making a similar suggestion. We can bikeshed the > name (it should certainly start with "array_"), but I think there's a very > good case for having an optimised implementation built in,

[PHP-DEV] Add is_vectorlike($array) function

2017-05-02 Thread Jesse Schalken
Related to the optimisation made by Sara Golemon here: https://github.com/php/php-src/commit/c74bc87c74f48bc55541b3bf2fc67d595f58a3b5 I often define a function like this, which checks if an array is "vector like" i.e. has keys 0,1,2..N: function is_vectorlike(array $a): bool { $i = 0;

Re: [PHP-DEV] array_values should be a no-op for packed layout arrays

2017-03-14 Thread Jesse Schalken
On Wed, Mar 15, 2017 at 10:39 AM, Sara Golemon wrote: > > Oh yeah, btw... six hours ago... > https://github.com/php/php-src/commit/c74bc87c74f48bc55541b3bf2fc67d > 595f58a3b5 > > -Sara > Awesome, thanks Sara.

Re: [PHP-DEV] array_values should be a no-op for packed layout arrays

2017-03-14 Thread Jesse Schalken
On Wed, Mar 15, 2017 at 3:48 AM, Sara Golemon wrote: > > Minor nit: [12=>'foo', 42=>'bar'] is not a packed array. > > [0=>'foo', 2=>'bar'] is however, so your primary point stands. > However it should be simple enough to detect when a packed array is > also vector-like (indexed

[PHP-DEV] array_values should be a no-op for packed layout arrays

2017-03-12 Thread Jesse Schalken
I noticed this commit recently in HHVM, which makes array_values() return the same array back if it's packed instead of building a copy. My understanding is PHP 7 also has packed arrays like HHVM, and my reading of

Re: [PHP-DEV] Idea: Function autoloading using dummy namespaces

2016-07-18 Thread Jesse Schalken
On Mon, Jul 18, 2016 at 9:55 AM, Nikita Popov wrote: > > A relaxed variant would only invoke the autoloader once for each > call, assuming that a function that is not loadable at one time will never > become loadable (which is of course a significant restriction). The

Re: [PHP-DEV] Idea: Function autoloading using dummy namespaces

2016-07-17 Thread Jesse Schalken
On Mon, Jul 18, 2016 at 4:53 AM, Nikita Popov wrote: > > Option B: foo() in namespace Bar will > a) Check if Bar\foo() exists > b) Otherwise check if foo() exists > c) Otherwise try to load 'Bar\foo' > d) Otherwise try to load 'foo' > e) If all fails, throw. > > This avoids

[PHP-DEV] Request for wiki karma

2016-07-13 Thread Jesse Schalken
Hi internals, I'd like wiki karma to write an RFC for the feature of setting properties/calling methods within an expression with the result of the object itself, eg $this->fooMethod(new FooParams() { setBlah(BLAH_CONST + 1), prop1 = $foo, prop3 = $builder->create() { prop1

Re: [PHP-DEV] Cascade Operator (was Re: [PHP-DEV] Proposal for php7 class method return)

2016-07-12 Thread Jesse Schalken
On Tue, Jul 12, 2016 at 6:36 PM, Rowan Collins wrote: > > Thinking about it, this becomes something more like a "with" keyword: > > with ( $counter ) { >count(); >count(); >count(); >count(); > } > > The semicolon suggests those lines are arbitrary

Re: [PHP-DEV] Proposal for php7 class method return

2016-07-11 Thread Jesse Schalken
On Mon, Jul 11, 2016 at 10:18 PM, Marco Pivetta wrote: > Hi Jesse, > > `return $this;` is a fairly common anti-pattern. It can be useful in few > edge-cases, like immutable APIs (CoW) and DSL builders, but it's usually a > bad idea. I ranted extensively about this at >

Re: [PHP-DEV] Proposal for php7 class method return

2016-07-10 Thread Jesse Schalken
On Sun, Jul 10, 2016 at 8:34 PM, Rasmus Schultz wrote: > > What you're really trying to accomplish is something like the ".." > operator found in some other languages - this is known as the "cascade > operator" in Dart, for example: > > >

Re: [PHP-DEV] [RFC DISCUSSION] var_info

2016-06-27 Thread Jesse Schalken
On Mon, Jun 27, 2016 at 3:19 AM, Fleshgrinder wrote: > I would like to start the discussion on the already announced var_info() > function. Especially the following open issues should be addressed > before going into voting: > > 1. Whether to output "negative zero float"

Re: [PHP-DEV] Set object properties inline

2016-06-01 Thread Jesse Schalken
come: expr_without_variable: /* ... */ | expr '{' inline_set_properties '}' ; inline_set_properties: /* empty */ | property_name '=' expr | property_name '=' expr ',' inline_set_properties ; > > Regards, > > > On Wed, Jun 1, 2016 at 5:49 AM, Peter Cowbur

Re: [PHP-DEV] Set object properties inline

2016-06-01 Thread Jesse Schalken
On Wed, Jun 1, 2016 at 7:49 PM, Peter Cowburn wrote: > > While it's not as concise as your example, anonymous classes can do this > already after a fashion. > > $this->fooMethod( > $arg1, > $arg2, > new class() extends FooParams { > // Constructor

Re: [PHP-DEV] Set object properties inline

2016-06-01 Thread Jesse Schalken
On Wed, Jun 1, 2016 at 7:40 PM, Lester Caine wrote: > Morphed into simply passing an array to the constructor ... > > $static1 = new Data\StaticVariable( array( > 'name' => 'variable name', > 'value'=> $unknown1, >

[PHP-DEV] Set object properties inline

2016-05-31 Thread Jesse Schalken
Hi internals, I often have code dealing with plain old PHP objects with properties and no methods, either as a substitute for keyword arguments, or to represent a JSON or YAML document for a web service, configuration file or schemaless database. At the moment, instantiating an object and

Re: [PHP-DEV] [RFC] Fix inconsistent behavior of $this variable

2016-05-24 Thread Jesse Schalken
On Tue, May 24, 2016 at 5:54 PM, Yasuo Ohgaki wrote: > Jesse, > > $this must be a object you're accessing. > Why? I consider it a kind of implied parameter. You can reassign self in Python for example. class MyClass: def foo(self, p1, p2): self = 7

Re: [PHP-DEV] [RFC] Fix inconsistent behavior of $this variable

2016-05-24 Thread Jesse Schalken
On Tue, May 24, 2016 at 5:18 PM, Dmitry Stogov wrote: > In fact $this is not a regular local variable and it must not be > re-assigned. > > You're just restating the premise for my question. Why is it not a regular local variable? Why must it not be reassigned?

Re: [PHP-DEV] [RFC] Fix inconsistent behavior of $this variable

2016-05-23 Thread Jesse Schalken
I'm curious, what is it about $this that makes it special in the first place? Can't it be a normal local variable that happens to already be assigned at the start of a method? On Tue, May 24, 2016 at 6:24 AM, Dmitry Stogov wrote: > Hi internals, > > > Please review the RFC. > >

Re: [PHP-DEV] Exception::getLine()

2016-05-19 Thread Jesse Schalken
On Fri, May 20, 2016 at 4:35 AM, Rasmus Schultz wrote: > This is inconsistent with at least JavaScript and C#, where the stack > trace is populated at the throw site. (Probably others?) > I'm not sure about C#, but in JavaScript (Node.js): function get_error() { return

Re: [PHP-DEV] Do symbol references always go through a hash table?

2016-05-17 Thread Jesse Schalken
On Wed, May 18, 2016 at 1:06 PM, Sara Golemon wrote: > Yes, but that doesn't mean you should micro-optimize around it. Just > write code that's easy to maintain and trust the compiler to do the > best job at making it not-slow. :) > > Do you happen to know whether or not HHVM

Re: [PHP-DEV] Do symbol references always go through a hash table?

2016-05-17 Thread Jesse Schalken
) On Wed, May 18, 2016 at 12:28 AM, Nikita Popov <nikita@gmail.com> wrote: > On Tue, May 17, 2016 at 3:03 PM, Jesse Schalken <m...@jesseschalken.com> > wrote: > >> Hi Internals, >> >> I'd like to know whether references to >> classes/functions/methods/

[PHP-DEV] Do symbol references always go through a hash table?

2016-05-17 Thread Jesse Schalken
Hi Internals, I'd like to know whether references to classes/functions/methods/properties/variables always go through a hash table at runtime, or if the name is optimised into a pointer or fixed offset. I recall seeing such an optimisation for local variables, but what about the others? Thanks

Re: [PHP-DEV] [RFC] Pipe Operator

2016-05-17 Thread Jesse Schalken
On Tue, May 17, 2016 at 9:14 PM, Rowan Collins wrote: > To reiterate my comments from earlier in the thread, I think the "$id = > $id" looks really weird here, and spoils the step-by-step layout - and, in > this case, the symmetry. > We have the same thing already when

Re: [PHP-DEV] [RFC] Pipe Operator

2016-05-17 Thread Jesse Schalken
Not sure if it's already been mentioned, but I've noticed this operator would be useful when you want to modify something but need to transform it before and after. For example, I have a class that serializes/deserializes arrays of strings, and I need to modify the array that it has encoded. The

Re: [PHP-DEV] Attributes/Annotations Case Study: Drupal

2016-05-05 Thread Jesse Schalken
If you're going to say "do what you want" with regards to annotations, then just let them be a text string. Parsing the annotation as PHP but not evaluating it as PHP seems a very strange and arbitrary half-way point. If the thing consuming the AST is expected to eval() it, then why didn't PHP do

Re: [PHP-DEV] Attributes/Annotations Case Study: Drupal

2016-05-04 Thread Jesse Schalken
On 4 May 2016 10:41 pm, "Rowan Collins" wrote: > > > You could either think of this as "setting lots of variables": > > new Foo { $bar = 1, $baz = 2 } > > or you could think of it as "an object literal like an array literal": > > new Foo { 'bar' => 1, 'baz' => 2 } > I

Re: [PHP-DEV] Attributes/Annotations Case Study: Drupal

2016-05-04 Thread Jesse Schalken
On Sat, Apr 30, 2016 at 9:47 AM, Larry Garfield wrote: > 3) Some way to provide a data definition for the annotation that can be > checked at compile time. This could be classes, a la Doctrine. It could be > a new Annotation type as others have suggested. It could be

Re: [PHP-DEV] [RFC] Pipe Operator

2016-05-04 Thread Jesse Schalken
On Sun, May 1, 2016 at 4:05 AM, Larry Garfield wrote: > > In a way... Sara, this syntax feels like it's only one step removed from > promises; if any of the chained steps involve IO, it becomes basically what > promises are for. Am I barking down the wrong tree, or is

Re: [PHP-DEV] [RFC] Pipe Operator

2016-05-03 Thread Jesse Schalken
On Tue, May 3, 2016 at 12:53 PM, Terry Cullen wrote: > ​Doesn't Nikic's scalar objects (https://github.com/nikic/scalar_objects) > more or less achieve the same thing while also cleaning up the std lib? > > $ret = scandir($arg) > ->filter(function(){}) >

Re: [PHP-DEV] [RFC] Pipe Operator

2016-05-03 Thread Jesse Schalken
I am very much in favour of this. I would typically write the example with an intermediate variable to avoid all the sad nesting. $files = scandir($arg); $files = array_filter($files, function ($x) { return $x !== '.' && $x !== '..'; }); $files = array_map(function ($x) use ($arg) { return $arg .

Re: [PHP-DEV] Forbid dynamic calls to scope introspection/modification functions

2016-05-01 Thread Jesse Schalken
I'm all in favour of this. It makes the language much more predictable and amenable to optimisation and static analysis overall, at the cost of what IMO is a very, very minor BC break. To think that all this time, functions I've written which accept a callable could be passed something like

Re: [PHP-DEV] [RFC:generics]

2016-04-29 Thread Jesse Schalken
On Sat, Apr 30, 2016 at 12:26 AM, guilhermebla...@gmail.com < guilhermebla...@gmail.com> wrote: > Wrong. This is documented here > https://docs.oracle.com/javase/tutorial/java/generics/upperBounded.html > and specifically states: > > To write the method that works on lists of Number and the

Re: [PHP-DEV] [RFC:generics]

2016-04-29 Thread Jesse Schalken
On Wed, Apr 27, 2016 at 6:50 AM, guilhermebla...@gmail.com < guilhermebla...@gmail.com> wrote: > Hi all, > > Yesterday I spent a considerable 2h talking about Generics in Doctrine > channel. > We discussed the specifics of each boundary that PHP's implementation could > take advantage. Here are

Re: [PHP-DEV] [RFC:generics]

2016-04-26 Thread Jesse Schalken
On Wed, Apr 27, 2016 at 6:50 AM, guilhermebla...@gmail.com < guilhermebla...@gmail.com> wrote: > Hi all, > > Yesterday I spent a considerable 2h talking about Generics in Doctrine > channel. > We discussed the specifics of each boundary that PHP's implementation could > take advantage. Here are

Re: [PHP-DEV] [RFC] Nullable Types

2016-04-25 Thread Jesse Schalken
On Sun, Apr 24, 2016 at 2:58 AM, Levi Morrison wrote: > On Sat, Apr 23, 2016 at 10:40 AM, Quim Calpe wrote: > > Option is no better than a union type with null[1]. If a language > requires an option to be unwrapped then it can do the same with some > type or null.

Re: [PHP-DEV][RFC] Callable Types

2016-04-23 Thread Jesse Schalken
turnsRef() {} // Fatal error: Declaration of ReturnVal::returnsRef() must be compatible with & Methods::returnsRef() function returnsVal() {} // ok } Otherwise it LGTM cheers On Sat, Apr 23, 2016 at 8:37 PM, Nikita Nefedov <inefe...@gmail.com> wrote: > On Sat, 23 Apr 2016

Re: [PHP-DEV][RFC] Callable Types

2016-04-23 Thread Jesse Schalken
This is great. The gaps in PHP's type annotations are slowly being filled. :) Are the rules for compatibility between callables the same rules for compatibility between methods in classes/interfaces? Because presently, this is allowed: interface Test { public function testMethod(); }

Re: [PHP-DEV] [RFC:generics]

2016-04-20 Thread Jesse Schalken
On Thu, Apr 21, 2016 at 8:56 AM, Rowan Collins wrote: > > I'm not quite sure what bounds would mean for anything other than classes > or interfaces. A generic type that specified that its type parameter must > be an int seems to me to be a non-generic type, because

Re: [PHP-DEV] [RFC:generics]

2016-04-20 Thread Jesse Schalken
"instanceof" implies to me that the right hand side is a class/interface name, since that's what's expected with the "instanceof" operator, rather than a type. If I can do "Foo>" I would expect to be able to do "if ($t instanceof array) ...", but I can't. I think unless the "instanceof" operator

Re: [PHP-DEV] Quick sanity check ...

2016-04-20 Thread Jesse Schalken
You're blaming humans (devs, testers etc) for a problem which could have been caught automatically (by a strictly enforced type annotation). It follows that you actually *want* writing PHP software to be inefficient, labour intensive and error-prone. On Thu, Apr 21, 2016 at 6:01 AM, Stanislav

Re: [PHP-DEV] Quick sanity check ...

2016-04-20 Thread Jesse Schalken
You can continue to use arrays for database records like you always have been. None of the new or proposed features are going to stop you. The concept of type annotations and type systems really has nothing to do with databases directly. It's about adding certainty with regards to the types that

Re: [PHP-DEV] [RFC] Nullable Types

2016-04-20 Thread Jesse Schalken
I read the RFC and it all sounds good to me. I appreciate the care taken to ensure method compatibility rules are correct, a smooth interop with =null, and to consider impact on union types if added later (? just becomes sugar). I'm not sure if it's been mentioned or not, but the position of the

Re: [PHP-DEV] [RFC:generics]

2016-04-20 Thread Jesse Schalken
Yes, if you have "class Box" and T is used for two things, then "they must be of the same type, but they can be any same type and that type must at least be Boxable". It means that Box can use a T as a Boxable (call Boxable methods on it, etc). On Thu, Apr 21, 2016 at 1:12 AM, Larry Garfield

Re: [PHP-DEV] Re: Improving PHP's type system

2016-04-20 Thread Jesse Schalken
On Wed, Apr 20, 2016 at 10:55 PM, Zeev Suraski <z...@zend.com> wrote: > > On 20 באפר׳ 2016, at 14:54, Jesse Schalken <m...@jesseschalken.com> wrote: > > If I had "scalar", "number" and ?T as types, the types I would need would > be: > >1.

Re: [PHP-DEV] Re: Improving PHP's type system

2016-04-20 Thread Jesse Schalken
I just noticed I originally missed "array" for #3. (The type is technically recursive, ie "type Jsonable = int|string|float|bool|null|array", but that's another can of worms.) On Wed, Apr 20, 2016 at 9:54 PM, Jesse Schalken <m...@jesseschalken.com> wrote: > If I

Re: [PHP-DEV] Re: Improving PHP's type system

2016-04-20 Thread Jesse Schalken
obably) 6. number 7. T|false 8. ?T 5 out of 8 still need a union. On Wed, Apr 20, 2016 at 9:01 PM, Zeev Suraski <z...@zend.com> wrote: > > > > -Original Message- > > From: jesseschal...@gmail.com [mailto:jesseschal...@gmail.com] On > > Behalf Of Jesse

Re: [PHP-DEV] Re: Improving PHP's type system

2016-04-20 Thread Jesse Schalken
.de> wrote: > On Wed, 2016-04-20 at 17:57 +1000, Jesse Schalken wrote: > > > > With unions: > > > > function foo(Bar|string $b) { > > > > if (is_string($b)) { > > // ... > > } else { > > // I know $b is a

Re: [PHP-DEV] Re: Improving PHP's type system

2016-04-20 Thread Jesse Schalken
On Thu, Apr 14, 2016 at 10:47 PM, Lin Yo-An wrote: > > I think the original purpose of adding type system in Hack, is to provide > just-in-time compilation, this provides more information to let compiler to > optimize the code with specific type. > > Last I checked, the

Re: [PHP-DEV] Re: Improving PHP's type system

2016-04-20 Thread Jesse Schalken
Without type annotations: function foo($b) { if (!is_string($b)) { // Ugh, why can't the language enforce this? throw new Exception("needed a string"); } } With type annotations: function foo(string $b) { // I know $b is a string. I don't need to check. :) } Without unions: function

Re: [PHP-DEV] [RFC:generics]

2016-04-19 Thread Jesse Schalken
I agree. On Wed, Apr 20, 2016 at 2:01 PM, Sara Golemon <poll...@php.net> wrote: > On Tue, Apr 19, 2016 at 7:56 PM, Jesse Schalken <m...@jesseschalken.com> > wrote: > >> class Collection {... > > > > I think the "where T is Traversable, T is Count

Re: [PHP-DEV] RFC: Anonymous Class Lexical Scope

2016-04-19 Thread Jesse Schalken
I'm not sure it matters, but there is some precedent for this in JavaScript/ES6: function foo(bar) { return new class { myBar = bar; getBar() { return this.myBar; } }(); } console.log(foo('hello').getBar()); // "hello" (You can actually reference

Re: [PHP-DEV] [RFC:generics]

2016-04-19 Thread Jesse Schalken
On Wed, Apr 20, 2016 at 8:22 AM, Sara Golemon wrote: > On Tue, Apr 19, 2016 at 1:16 PM, Mathieu Rochette > wrote: > > about the upper bounds, have you consider another way of describing the > > constraints, eg: > > > > class Box where T is Boxable > > > >

Re: [PHP-DEV] RFC about automatic template escaping

2016-03-21 Thread Jesse Schalken
I think having the behaviour of language features depend in an incompatible way on a global runtime setting is a bad idea because it creates nonlocal effects and means code cannot be realiably composed. Effectively, every function and method will have an implicit assumption about whether or not it

Re: [PHP-DEV] RFC about automatic template escaping

2016-03-21 Thread Jesse Schalken
On Mon, Mar 21, 2016 at 4:53 PM, Daniel Beardsley wrote: > > This approach has the smell of magic quotes which we got rid of for > > very good reason. XHP is much more explicit in separating markup from > > data and relies far less (not at all when you do it right) on escape

Re: [PHP-DEV] RFC about automatic template escaping

2016-03-21 Thread Jesse Schalken
Wouldn't this __auto_escape setting effectively break libraries that depend on it being on or off? People often write code to generate HTML like this: ob_start(); ?> some HTML more HTML wrote: > Hi Daniel, > > On Mon, Mar 21, 2016 at 7:11 AM, Daniel Beardsley >

Re: [PHP-DEV] RFC about automatic template escaping

2016-03-20 Thread Jesse Schalken
I agree XHP really is the right solution for this problem. It enables HTML to be created structurally and composably with a concise inline syntax, just like JSX/React does for JavaScript, and just like LINQ does for SQL in C#. It's* much* better than passing around snippets of HTML as strings that

Re: [PHP-DEV] Re: [RFC] Traits with interfaces

2016-03-05 Thread Jesse Schalken
Your class 'c' example (last link) only shows method 'bar' (the trait method) and not 'bat' (the aliased metod). The class has both, but 'bat' is hidden from get_class_methods() because it is private. On 6 Mar 2016 10:16 am, "Davey Shafik" wrote: > On Fri, Mar 4, 2016 at 2:06 AM,