Welcome! Log In Create A New Profile

Advanced

[PHP-DEV] rfc concepts

Posted by Kelt Dockins 
Kelt Dockins
[PHP-DEV] rfc concepts
April 14, 2017 06:40AM
Hi everybody,


I've been using php for many years now and it really is a great language. My friend and I were talking about additional things we would want in php - sort of like a wishlist. I came up with 3 things that I think would make php even more awesome and I wanted to share these concepts with this list and I'd love to get feedback. I haven't done any c programming in years but I'd be open to working on these concepts if enough people wanted them.



1. use strict mode


```

class Bar { }


class Foo

{
use strict;

}


$bar = new Bar;

$bar->thing = 1; // no problem


$foo = new Foo;

$foo->thing = 1; // throws error because thing attribute does not exists

```



2. type hinting class properties


```

class Foo

{
public $thing : int;

}


$foo = new Foo;

$foo->thing = 1; // works fine

$foo->thing = 'string'; // throws Typehint

```


3. auto properties


```

class Foo

{

private $thing1 {

get, set

};


private $thing2 {

get

};


private $thing3 {

set

};

}


$foo = new Foo;

$foo->thing1 = 'asdf';

echo $foo->thing1; // echos 'asdf'


$foo->thing2 = 'asdf'; // throws error because no setter


$foo->thing3 = ''asdf'; // sets thing3

echo $foo->thing3; // throws error because no getter

```


I'd love to hear what you all have to say about these things. Thanks in advance for your feedback and time!


- Kelt
Sherif Ramadan
Re: [PHP-DEV] rfc concepts
April 14, 2017 07:20AM
There have already been several such proposals made in past years, and
discussed at length here on the mailing list.

See C# Style Accessors past RFC:
https://wiki.php.net/rfc/propertygetsetsyntax-v1.2
and alternatives:
https://wiki.php.net/rfc/propertygetsetsyntax-alternative-typehinting-syntax


Since PHP 7 already supports scalar type hints and strict mode, as well as
magic getters/setters, pretty much all of your aforementioned concepts are
already possible in PHP with a bit of boiler plate. The declarative
accessors obviously have some benefits like less verbosity and more concise
syntax, but we've been down this road before in the past and I'd suggest
reading the discussions around those RFCs, with similar ideas, which were
declined or withdrawn and coming up with a more constructive approach if
you want it to gain any critical mass. It's going to be a tough sell if you
just come back with the same approach.

On Thu, Apr 13, 2017 at 9:40 PM, Kelt Dockins <[email protected]> wrote:

> Hi everybody,
>
>
> I've been using php for many years now and it really is a great language.
> My friend and I were talking about additional things we would want in php -
> sort of like a wishlist. I came up with 3 things that I think would make
> php even more awesome and I wanted to share these concepts with this list
> and I'd love to get feedback. I haven't done any c programming in years but
> I'd be open to working on these concepts if enough people wanted them.
>
>
>
> 1. use strict mode
>
>
> ```
>
> class Bar { }
>
>
> class Foo
>
> {
> use strict;
>
> }
>
>
> $bar = new Bar;
>
> $bar->thing = 1; // no problem
>
>
> $foo = new Foo;
>
> $foo->thing = 1; // throws error because thing attribute does not
> exists
>
> ```
>
>
>
> 2. type hinting class properties
>
>
> ```
>
> class Foo
>
> {
> public $thing : int;
>
> }
>
>
> $foo = new Foo;
>
> $foo->thing = 1; // works fine
>
> $foo->thing = 'string'; // throws Typehint
>
> ```
>
>
> 3. auto properties
>
>
> ```
>
> class Foo
>
> {
>
> private $thing1 {
>
> get, set
>
> };
>
>
> private $thing2 {
>
> get
>
> };
>
>
> private $thing3 {
>
> set
>
> };
>
> }
>
>
> $foo = new Foo;
>
> $foo->thing1 = 'asdf';
>
> echo $foo->thing1; // echos 'asdf'
>
>
> $foo->thing2 = 'asdf'; // throws error because no setter
>
>
> $foo->thing3 = ''asdf'; // sets thing3
>
> echo $foo->thing3; // throws error because no getter
>
> ```
>
>
> I'd love to hear what you all have to say about these things. Thanks in
> advance for your feedback and time!
>
>
> - Kelt
>
Sorry, only registered users may post in this forum.

Click here to login