On Thu, 13 Feb 2020 at 08:58, Rowan Tommins <rowan.coll...@gmail.com> wrote:

> On 12 February 2020 23:12:34 GMT+00:00, Manuel Canga <
> manuelca...@gmail.com> wrote:
> >El mié., 12 feb. 2020 23:01, Rowan Tommins <rowan.coll...@gmail.com>
> >escribió:
> >In your example, you has the same options:
> >
> >>
> >1. Change import
> >2. Add namespace:
> >
> >['Acme\Global\I18N',\translate::function]
>
>
> There is no collision between 'Foo::translate()' and 'translate()', so
> there is no reason to change the import. That's true of executing the
> functions, so it should remain be true of resolving them to strings.
>
> There is collision with import which you added.



>
>
> >Explain:
> >
> >When you do: [ class, method ] or [ $object, method ]. Method has not
> >namespace, you write it without namespace( like global functions )
>
>
> I think this is where we are thinking differently. A method name is not
> "like a global function", it's just a name; it doesn't belong in the same
> category.
>
> You might have any number of classes that use the same method name, but
> with completely different parameters and purpose, so "a method named foo"
> isn't a useful concept outside some specific class or interface.
>
> On the other hand, you can only have one function with a particular
> fully-qualified name, and the proposed feature is a way of referencing that.
>
>
Function as callable is different as regular function. Example:

http://sandbox.onlinephpfunctions.com/code/99408213d1ed740f60471646f16f9765d7efa93e

namespace MyProject;

function my_function() {
  //....
}

my_function(); // it calls to \MyProject\my_function

array_map('my_function', [] ); //*

* Here, 'my_function' is only a string. Maybe a global function( without
namespace  ) or maybe a method or other case. With native array_map is a
global function. However, you can have a function like this:

function array_map( $method, $array) {
  \Collection::$method( $array );
}

In both cases, you could do:

array_map(\my_function::function, [] );





>
>
> >Other example:
> >
> >$class = \MyClass::class;
> >$method = \method::function;
> >
> >and...
> >
> >$class = '\MyClass';
> >$method = 'method';
> >
> >$obj = new $class();
> >$obj->$method();
> >
> >Both are the same, but first is more semantic.
>
>
> This isn't semantic at all - it works only because \method::function
> happens to return the string you want, but so does \method::class; neither
> is actually labelling it as what it is, which is a method within class
> \MyClass.
>
> Importantly, it might not work at all, if ::function gives an error if
> the function doesn't exist.
>
>
::function only would retrieve string, like as ::class, exists or not. In
fach, that code might not work at all due to class. What matter if Class
does't exist ?. ::class doesn't produce error. Look:
http://sandbox.onlinephpfunctions.com/code/0a8466a00974bc1ffc12b219569ced55753327bd

If class doesn't exist, nothing happend.


Thank, Rowan. You points of view are very interesting.

Reply via email to