Danack / FunctionTypes

php needs function types
MIT License
3 stars 2 forks source link

Referring to types #6

Open Danack opened 4 years ago

Danack commented 4 years ago

So what happens?

class Foo {}
echo Foo::class; //output is 'Foo'

typedef Bar  = callable(int $x, int $y);
echo Bar::class; // output is 'Bar' ....?

Needs thinking about.

DennisBirkholz commented 4 years ago

Hi Dan,

thanks for thinking about/working on this whole topic. I think the main problem we have here is that Classes, Functions and Constants are in separate symbol tables. If they where in one unified symbol table, you could just reference classes and functions by name:

<?php
$callable = strlen;
echo $callable("abc"); // 3

Maybe PHP 8 is the right place for doing this? There may be conflicts with constants, but I really don't think using a constant named strlen when there is a strlen function is a good idea in the first place.

Danack commented 4 years ago

Any solution for referencing callables, would need to cover all of the types, so maybe something like this.

But I'm really unsure.

DennisBirkholz commented 4 years ago

I saw this before. The need for the extra syntax $() seems to be the problem to decide whether you reference a constant or a "type". IMHO if both where in the same symbol table, the extra syntax would not be needed. But I do not have sufficient knowledge of PHP internals to make this a statement, it is just a guess.