Change -> to dot(.)

php.internals

Khawer .

9 years ago
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.

Ilija Tovilo

9 years ago
The dot is already the string concatenation operator. This would be a horrible migration process. The PHP team is never going to upset the developer experience that much for a purely cosmetic change. Also, C and C++ use the -> symbol, two major languages. Regards On 6 Jul 2017, 08:13 +0200, Khawer . <khaweronline@gmail.com>, wrote:

Marco Pivetta

9 years ago
What's the point? Sorry for the snarky response, but it had to be done 😂 On 6 Jul 2017 8:13 AM, "Khawer ." <khaweronline@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.

Stephen Reay

9 years ago
> On 6 Jul 2017, at 13:13, Khawer . <khaweronline@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()

Niklas Keller

9 years ago
Stephen Reay <php-lists@koalephant.com> schrieb am Do., 6. Juli 2017, 09:04:
> > > On 6 Jul 2017, at 13:13, Khawer . <khaweronline@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

Michał Brzuchalski

9 years ago
06.07.2017 09:43 "Niklas Keller" <me@kelunik.com> napisał(a):
> > Stephen Reay <php-lists@koalephant.com> schrieb am Do., 6. Juli 2017,
09:04:
> > > > > > On 6 Jul 2017, at 13:13, Khawer . <khaweronline@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.
That would be huge BC break because plus on string which ale numerical is adding numbers so result fir now would be sum. Not concatenated string.

lists@rhsoft.net

9 years ago
Am 06.07.2017 um 08:13 schrieb Khawer.:
> 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(.)
to gain what?
> We will still
who is "we"
> keep "->" until PHP 8 to maintain backward compatibility
and then force to rewrite every single piece of code out there? that's a "have a solution and seeking for the problem"