Stephen Reay <php-li...@koalephant.com> schrieb am Do., 6. Juli 2017, 09:04:

>
> > On 6 Jul 2017, at 13:13, Khawer . <khaweronl...@gmail.com> wrote:
> >
> > In all major programming languages we access object properties and
> methods
> > using dot(.).
> >
> > C#:
> > Abc Abc = new Abc();
> > Abc.method();
> >
> > Java:
> > Abc Abc = new Abc();
> > Abc.method();
> >
> > JavaScript:
> > var apple = new function() {
> >    this.name = "Test";
> > }
> > alert(apple.name());
> >
> >
> > Why not to make PHP similar to these languages by allowing to access
> object
> > properties and methods using dot(.). We will still keep "->" until PHP 8
> to
> > maintain backward compatibility.
>
> In each of those languages, the plus operator is used for string
> concatenation.
>
> In PHP the dot operator is used for string concatenation, and objects can
> be cast to strings when concatenating, so how do you differentiate the two
> calls at the end of this block:
>
> class Bar {
>         public function baz() {…}
>
>         public function __toString(): string {...}
> }
>
> function baz(): string {…}
>
> $foo = new Bar();
> $foo.baz(); // call method Baz on object $foo
> $foo.baz(); // concat the result of casting $foo to string, with the
> result of calling baz()
>

Obviously by using plus for concatenation.

Regards, Niklas

>

Reply via email to