Hi,
I would need your help with one idea. I'm working on one RFC that I'm would
like to submit. Idea is that after you initialize object eg. after
constructor returns, object would be locked, and you wouldn't be able to
change properties on that object anymore. It would like this:
<?php
immutable class Email {
public $email; public function __construct($email){ $this->email = $email; }
}
$email = new Email("example@email.com");
After instance of class is created, object is "frozen" so call like this
$email->email = "new@email.com";
Would result in error.
I have already implementation up to certain degree, but I need one advice
from more experienced developers. Where is the place where I could put
logic to lock object after the constructor has finished? Maybe in zend vm
on ZEND_NEW token?
Some constraints are needed:
- Child class that extends immutable class must be defined as immutable
also. - If property on immutable class contains object, it must be instance
of immutable class. - You can not have immutability per property, it either whole class or
none.
Thank you all in advance.
--
Silvio Marijić
Software Engineer
2e Systems
Hi Silvio,
Look into my talk about final properties https://marc.info/?
t=145979255800003&r=1&w=2 maybe there would be something usefull.
There is also talk about mutable and immutable properties and other class
modifiers also about var and val.
I'm not sure that it should be class midifier rather than proprty modifier
keyword.
regards,
Michał Brzuchalski
2016-08-08 12:31 GMT+02:00 Silvio Marijić marijic.silvio@gmail.com:
Hi,
I would need your help with one idea. I'm working on one RFC that I'm would
like to submit. Idea is that after you initialize object eg. after
constructor returns, object would be locked, and you wouldn't be able to
change properties on that object anymore. It would like this:<?php
immutable class Email {
public $email; public function __construct($email){ $this->email = $email; }
}
$email = new Email("example@email.com");After instance of class is created, object is "frozen" so call like this
$email->email = "new@email.com";
Would result in error.
I have already implementation up to certain degree, but I need one advice
from more experienced developers. Where is the place where I could put
logic to lock object after the constructor has finished? Maybe in zend vm
on ZEND_NEW token?Some constraints are needed:
- Child class that extends immutable class must be defined as immutable
also.- If property on immutable class contains object, it must be instance
of immutable class.- You can not have immutability per property, it either whole class or
none.Thank you all in advance.
--
Silvio Marijić
Software Engineer
2e Systems
--
pozdrawiam
Michał Brzuchalski
I see your standpoint, but I think it could cause confusion because of
final classes. I think "immutable" is more suited here.
What I try to achieve is something similar like case classes in Scala.
Best regards,
2016-08-08 13:16 GMT+02:00 Michał Brzuchalski michal@brzuchalski.com:
Hi Silvio,
Look into my talk about final properties https://marc.info/?
t=145979255800003&r=1&w=2 maybe there would be something usefull.
There is also talk about mutable and immutable properties and other class
modifiers also about var and val.
I'm not sure that it should be class midifier rather than proprty modifier
keyword.regards,
Michał Brzuchalski
2016-08-08 12:31 GMT+02:00 Silvio Marijić marijic.silvio@gmail.com:
Hi,
I would need your help with one idea. I'm working on one RFC that I'm
would
like to submit. Idea is that after you initialize object eg. after
constructor returns, object would be locked, and you wouldn't be able to
change properties on that object anymore. It would like this:<?php
immutable class Email {
public $email; public function __construct($email){ $this->email = $email; }
}
$email = new Email("example@email.com");After instance of class is created, object is "frozen" so call like this
$email->email = "new@email.com";
Would result in error.
I have already implementation up to certain degree, but I need one advice
from more experienced developers. Where is the place where I could put
logic to lock object after the constructor has finished? Maybe in zend vm
on ZEND_NEW token?Some constraints are needed:
- Child class that extends immutable class must be defined as
immutable
also.- If property on immutable class contains object, it must be instance
of immutable class.- You can not have immutability per property, it either whole class or
none.Thank you all in advance.
--
Silvio Marijić
Software Engineer
2e Systems--
pozdrawiamMichał Brzuchalski
--
Silvio Marijić
Software Engineer
2e Systems
Btw, I was not aware that there was already conversation on immutable
classes.
2016-08-08 14:31 GMT+02:00 Silvio Marijić marijic.silvio@gmail.com:
I see your standpoint, but I think it could cause confusion because of
final classes. I think "immutable" is more suited here.
What I try to achieve is something similar like case classes in Scala.Best regards,
2016-08-08 13:16 GMT+02:00 Michał Brzuchalski michal@brzuchalski.com:
Hi Silvio,
Look into my talk about final properties https://marc.info/?
t=145979255800003&r=1&w=2 maybe there would be something usefull.
There is also talk about mutable and immutable properties and other class
modifiers also about var and val.
I'm not sure that it should be class midifier rather than proprty
modifier keyword.regards,
Michał Brzuchalski
2016-08-08 12:31 GMT+02:00 Silvio Marijić marijic.silvio@gmail.com:
Hi,
I would need your help with one idea. I'm working on one RFC that I'm
would
like to submit. Idea is that after you initialize object eg. after
constructor returns, object would be locked, and you wouldn't be able to
change properties on that object anymore. It would like this:<?php
immutable class Email {
public $email; public function __construct($email){ $this->email = $email; }
}
$email = new Email("example@email.com");After instance of class is created, object is "frozen" so call like this
$email->email = "new@email.com";
Would result in error.
I have already implementation up to certain degree, but I need one advice
from more experienced developers. Where is the place where I could put
logic to lock object after the constructor has finished? Maybe in zend vm
on ZEND_NEW token?Some constraints are needed:
- Child class that extends immutable class must be defined as
immutable
also.- If property on immutable class contains object, it must be instance
of immutable class.- You can not have immutability per property, it either whole class
or
none.Thank you all in advance.
--
Silvio Marijić
Software Engineer
2e Systems--
pozdrawiamMichał Brzuchalski
--
Silvio Marijić
Software Engineer
2e Systems
--
Silvio Marijić
Software Engineer
2e Systems
Sure my final properties was first thought, lately in discuccion it turns
into immutable, sealed and final see here
https://marc.info/?l=php-internals&m=146005058530881&w=2
Have you also read about Immutable modifier from last year?
http://marc.info/?t=144766539400001&r=1&w=2 it's exactly about immutable
classes!
2016-08-08 14:46 GMT+02:00 Silvio Marijić marijic.silvio@gmail.com:
Btw, I was not aware that there was already conversation on immutable
classes.2016-08-08 14:31 GMT+02:00 Silvio Marijić marijic.silvio@gmail.com:
I see your standpoint, but I think it could cause confusion because of
final classes. I think "immutable" is more suited here.
What I try to achieve is something similar like case classes in Scala.Best regards,
2016-08-08 13:16 GMT+02:00 Michał Brzuchalski michal@brzuchalski.com:
Hi Silvio,
Look into my talk about final properties https://marc.info/?
t=145979255800003&r=1&w=2 maybe there would be something usefull.
There is also talk about mutable and immutable properties and other
class modifiers also about var and val.
I'm not sure that it should be class midifier rather than proprty
modifier keyword.regards,
Michał Brzuchalski
2016-08-08 12:31 GMT+02:00 Silvio Marijić marijic.silvio@gmail.com:
Hi,
I would need your help with one idea. I'm working on one RFC that I'm
would
like to submit. Idea is that after you initialize object eg. after
constructor returns, object would be locked, and you wouldn't be able to
change properties on that object anymore. It would like this:<?php
immutable class Email {
public $email; public function __construct($email){ $this->email = $email; }
}
$email = new Email("example@email.com");After instance of class is created, object is "frozen" so call like this
$email->email = "new@email.com";
Would result in error.
I have already implementation up to certain degree, but I need one
advice
from more experienced developers. Where is the place where I could put
logic to lock object after the constructor has finished? Maybe in zend
vm
on ZEND_NEW token?Some constraints are needed:
- Child class that extends immutable class must be defined as
immutable
also.- If property on immutable class contains object, it must be
instance
of immutable class.- You can not have immutability per property, it either whole class
or
none.Thank you all in advance.
--
Silvio Marijić
Software Engineer
2e Systems--
pozdrawiamMichał Brzuchalski
--
Silvio Marijić
Software Engineer
2e Systems--
Silvio Marijić
Software Engineer
2e Systems
--
pozdrawiam
Michał Brzuchalski
May be better to do as immutable arrays?
const = new Email;
it will be a super global immutable instance of Email.
May be better to do as immutable arrays?
const EmailObject = new Email;
It will be a super global immutable instance of Email.
2016-08-08 14:47 GMT+02:00 S.A.N ua.san.alex@gmail.com:
May be better to do as immutable arrays?
const = new Email;
it will be a super global immutable instance of Email.
I think you've missunderstood concept of immutable classes.
--
pozdrawiam
Michał Brzuchalski
@Michal, well no I did read it. I see that there is not much going on there
since last year. Did you tried to implement it ?
2016-08-08 14:49 GMT+02:00 Michał Brzuchalski michal@brzuchalski.com:
2016-08-08 14:47 GMT+02:00 S.A.N ua.san.alex@gmail.com:
May be better to do as immutable arrays?
const = new Email;
it will be a super global immutable instance of Email.
I think you've missunderstood concept of immutable classes.
--
pozdrawiamMichał Brzuchalski
--
Silvio Marijić
Software Engineer
2e Systems
@Silvio I've tried to implement final
https://github.com/php/php-src/compare/master...brzuchal:final-properties
but haven't found time to implement immutable and sealed, AFAIK I had
problems with OPcache enabled, you need to remember to run every test after
compile with opcache enabled in CLI.
2016-08-08 15:00 GMT+02:00 Silvio Marijić marijic.silvio@gmail.com:
@Michal, well no I did read it. I see that there is not much going on
there since last year. Did you tried to implement it ?2016-08-08 14:49 GMT+02:00 Michał Brzuchalski michal@brzuchalski.com:
2016-08-08 14:47 GMT+02:00 S.A.N ua.san.alex@gmail.com:
May be better to do as immutable arrays?
const = new Email;
it will be a super global immutable instance of Email.
I think you've missunderstood concept of immutable classes.
--
pozdrawiamMichał Brzuchalski
--
Silvio Marijić
Software Engineer
2e Systems
--
pozdrawiam
Michał Brzuchalski
@Michal Would you consider cooperating on implementing immutable and sealed
modifiers?
2016-08-08 15:20 GMT+02:00 Michał Brzuchalski michal@brzuchalski.com:
@Silvio I've tried to implement final https://github.com/php/
php-src/compare/master...brzuchal:final-properties but haven't found time
to implement immutable and sealed, AFAIK I had problems with OPcache
enabled, you need to remember to run every test after compile with opcache
enabled in CLI.2016-08-08 15:00 GMT+02:00 Silvio Marijić marijic.silvio@gmail.com:
@Michal, well no I did read it. I see that there is not much going on
there since last year. Did you tried to implement it ?2016-08-08 14:49 GMT+02:00 Michał Brzuchalski michal@brzuchalski.com:
2016-08-08 14:47 GMT+02:00 S.A.N ua.san.alex@gmail.com:
May be better to do as immutable arrays?
const = new Email;
it will be a super global immutable instance of Email.
I think you've missunderstood concept of immutable classes.
--
pozdrawiamMichał Brzuchalski
--
Silvio Marijić
Software Engineer
2e Systems--
pozdrawiamMichał Brzuchalski
--
Silvio Marijić
Software Engineer
2e Systems
It is great to hear somone is interested so why not. My lately discussion
found usefull implementing 3 keywords, such as:
- immutable for the functionality you are currently working on.
- sealed for the above plus type not changeable.
- final for the above plus not being overridable.
But all of them should be implemented in different RFC's starting from
Immutable because it's base point to toher two keywords.
Whole idea needs refreshing discussion to clarify idea so it can success.
2016-08-08 15:23 GMT+02:00 Silvio Marijić marijic.silvio@gmail.com:
@Michal Would you consider cooperating on implementing immutable and
sealed modifiers?2016-08-08 15:20 GMT+02:00 Michał Brzuchalski michal@brzuchalski.com:
@Silvio I've tried to implement final https://github.com/php/p
hp-src/compare/master...brzuchal:final-properties but haven't found time
to implement immutable and sealed, AFAIK I had problems with OPcache
enabled, you need to remember to run every test after compile with opcache
enabled in CLI.2016-08-08 15:00 GMT+02:00 Silvio Marijić marijic.silvio@gmail.com:
@Michal, well no I did read it. I see that there is not much going on
there since last year. Did you tried to implement it ?2016-08-08 14:49 GMT+02:00 Michał Brzuchalski michal@brzuchalski.com:
2016-08-08 14:47 GMT+02:00 S.A.N ua.san.alex@gmail.com:
May be better to do as immutable arrays?
const = new Email;
it will be a super global immutable instance of Email.
I think you've missunderstood concept of immutable classes.
--
pozdrawiamMichał Brzuchalski
--
Silvio Marijić
Software Engineer
2e Systems--
pozdrawiamMichał Brzuchalski
--
Silvio Marijić
Software Engineer
2e Systems
--
pozdrawiam
Michał Brzuchalski
It's great that you are up of this.
I think it will be great to see this one in action.
I agree that we should separate them into separate RFC-s.
2016-08-08 15:51 GMT+02:00 Michał Brzuchalski michal@brzuchalski.com:
It is great to hear somone is interested so why not. My lately discussion
found usefull implementing 3 keywords, such as:
- immutable for the functionality you are currently working on.
- sealed for the above plus type not changeable.
- final for the above plus not being overridable.
But all of them should be implemented in different RFC's starting from
Immutable because it's base point to toher two keywords.
Whole idea needs refreshing discussion to clarify idea so it can success.2016-08-08 15:23 GMT+02:00 Silvio Marijić marijic.silvio@gmail.com:
@Michal Would you consider cooperating on implementing immutable and
sealed modifiers?2016-08-08 15:20 GMT+02:00 Michał Brzuchalski michal@brzuchalski.com:
@Silvio I've tried to implement final https://github.com/php/p
hp-src/compare/master...brzuchal:final-properties but haven't found
time to implement immutable and sealed, AFAIK I had problems with OPcache
enabled, you need to remember to run every test after compile with opcache
enabled in CLI.2016-08-08 15:00 GMT+02:00 Silvio Marijić marijic.silvio@gmail.com:
@Michal, well no I did read it. I see that there is not much going on
there since last year. Did you tried to implement it ?2016-08-08 14:49 GMT+02:00 Michał Brzuchalski michal@brzuchalski.com:
2016-08-08 14:47 GMT+02:00 S.A.N ua.san.alex@gmail.com:
May be better to do as immutable arrays?
const = new Email;
it will be a super global immutable instance of Email.
I think you've missunderstood concept of immutable classes.
--
pozdrawiamMichał Brzuchalski
--
Silvio Marijić
Software Engineer
2e Systems--
pozdrawiamMichał Brzuchalski
--
Silvio Marijić
Software Engineer
2e Systems--
pozdrawiamMichał Brzuchalski
--
Silvio Marijić
Software Engineer
2e Systems
It's great that you are up of this.
I think it will be great to see this one in action.I agree that we should separate them into separate RFC-s.
2016-08-08 15:51 GMT+02:00 Michał Brzuchalski michal@brzuchalski.com:
It is great to hear somone is interested so why not. My lately discussion
found usefull implementing 3 keywords, such as:
- immutable for the functionality you are currently working on.
- sealed for the above plus type not changeable.
- final for the above plus not being overridable.
But all of them should be implemented in different RFC's starting from
Immutable because it's base point to toher two keywords.
Whole idea needs refreshing discussion to clarify idea so it can success.
I would like to offer my support. I might not be as familiar as you guys
with the C source but if you need anything (e.g. documentation, RFC
writing, testing, ...) let me know.
--
Richard "Fleshgrinder" Fussenegger
@Fleshgrinder, Thanks, every help is welcome.
2016-08-08 18:44 GMT+02:00 Fleshgrinder php@fleshgrinder.com:
It's great that you are up of this.
I think it will be great to see this one in action.I agree that we should separate them into separate RFC-s.
2016-08-08 15:51 GMT+02:00 Michał Brzuchalski michal@brzuchalski.com:
It is great to hear somone is interested so why not. My lately
discussion
found usefull implementing 3 keywords, such as:
- immutable for the functionality you are currently working on.
- sealed for the above plus type not changeable.
- final for the above plus not being overridable.
But all of them should be implemented in different RFC's starting from
Immutable because it's base point to toher two keywords.
Whole idea needs refreshing discussion to clarify idea so it can
success.I would like to offer my support. I might not be as familiar as you guys
with the C source but if you need anything (e.g. documentation, RFC
writing, testing, ...) let me know.--
Richard "Fleshgrinder" Fussenegger
--
Silvio Marijić
Software Engineer
2e Systems
@Fleshgrinder thanks,
my knowledge of C allowed me to implement some features experimentally.
When problem occurs then I'll find any needed help because I think this
feature is needed.
Personally I don't have wiki karma so help in writing RFC if you have karma
could help us very much.
2016-08-08 19:16 GMT+02:00 Silvio Marijić marijic.silvio@gmail.com:
@Fleshgrinder, Thanks, every help is welcome.
2016-08-08 18:44 GMT+02:00 Fleshgrinder php@fleshgrinder.com:
It's great that you are up of this.
I think it will be great to see this one in action.I agree that we should separate them into separate RFC-s.
2016-08-08 15:51 GMT+02:00 Michał Brzuchalski michal@brzuchalski.com:
It is great to hear somone is interested so why not. My lately
discussion
found usefull implementing 3 keywords, such as:
- immutable for the functionality you are currently working on.
- sealed for the above plus type not changeable.
- final for the above plus not being overridable.
But all of them should be implemented in different RFC's starting from
Immutable because it's base point to toher two keywords.
Whole idea needs refreshing discussion to clarify idea so it can
success.I would like to offer my support. I might not be as familiar as you guys
with the C source but if you need anything (e.g. documentation, RFC
writing, testing, ...) let me know.--
Richard "Fleshgrinder" Fussenegger--
Silvio Marijić
Software Engineer
2e Systems
--
pozdrawiam
Michał Brzuchalski
I see Reflection is still todo; should there be a similar escape hatch to ReflectionMethod::setAccessible()?
This would allow things like: https://gist.github.com/fredemmott/01ad55c0c03c8d7ba62bbd6e9fb23686 https://gist.github.com/fredemmott/01ad55c0c03c8d7ba62bbd6e9fb23686 (apologies for the hack-like syntax) - the ‘every property must be a constructor parameter’ approach in the RFC seems like it would rapidly become unwieldy for classes with a large number of properties.
Regards,
- Fred
Hi,
I would need your help with one idea. I'm working on one RFC that I'm would
like to submit. Idea is that after you initialize object eg. after
constructor returns, object would be locked, and you wouldn't be able to
change properties on that object anymore. It would like this:<?php
immutable class Email {
public $email; public function __construct($email){ $this->email = $email; }
}
$email = new Email("example@email.com");After instance of class is created, object is "frozen" so call like this
$email->email = "new@email.com";
Would result in error.
I have already implementation up to certain degree, but I need one advice
from more experienced developers. Where is the place where I could put
logic to lock object after the constructor has finished? Maybe in zend vm
on ZEND_NEW token?Some constraints are needed:
- Child class that extends immutable class must be defined as immutable
also.- If property on immutable class contains object, it must be instance
of immutable class.- You can not have immutability per property, it either whole class or
none.Thank you all in advance.
--
Silvio Marijić
Software Engineer
2e Systems
@Fred
Thanks for taking interest. I still need to fully patch reflection
extension for this. We had more important discussions in the past two weeks.
Cheers,
Silvio
2016-09-09 21:46 GMT+02:00 Fred Emmott fred@fredemmott.co.uk:
I see Reflection is still todo; should there be a similar escape hatch to
ReflectionMethod::setAccessible()?This would allow things like: https://gist.github.com/fredemmott/
01ad55c0c03c8d7ba62bbd6e9fb23686 (apologies for the hack-like syntax) -
the ‘every property must be a constructor parameter’ approach in the RFC
seems like it would rapidly become unwieldy for classes with a large number
of properties.Regards,
- Fred
On Aug 8, 2016, at 3:31 AM, Silvio Marijić marijic.silvio@gmail.com
wrote:Hi,
I would need your help with one idea. I'm working on one RFC that I'm would
like to submit. Idea is that after you initialize object eg. after
constructor returns, object would be locked, and you wouldn't be able to
change properties on that object anymore. It would like this:<?php
immutable class Email {
public $email; public function __construct($email){ $this->email = $email; }
}
$email = new Email("example@email.com");After instance of class is created, object is "frozen" so call like this
$email->email = "new@email.com";
Would result in error.
I have already implementation up to certain degree, but I need one advice
from more experienced developers. Where is the place where I could put
logic to lock object after the constructor has finished? Maybe in zend vm
on ZEND_NEW token?Some constraints are needed:
- Child class that extends immutable class must be defined as immutable
also.- If property on immutable class contains object, it must be instance
of immutable class.- You can not have immutability per property, it either whole class or
none.Thank you all in advance.
--
Silvio Marijić
Software Engineer
2e Systems
--
Silvio Marijić
Software Engineer
2e Systems
It will be patched before this RFC goes into official discussion.
2016-09-09 22:01 GMT+02:00 Silvio Marijić marijic.silvio@gmail.com:
@Fred
Thanks for taking interest. I still need to fully patch reflection
extension for this. We had more important discussions in the past two weeks.Cheers,
Silvio2016-09-09 21:46 GMT+02:00 Fred Emmott fred@fredemmott.co.uk:
I see Reflection is still todo; should there be a similar escape hatch
to ReflectionMethod::setAccessible()?This would allow things like: https://gist.github.com/
fredemmott/01ad55c0c03c8d7ba62bbd6e9fb23686 (apologies for the hack-like
syntax) - the ‘every property must be a constructor parameter’ approach in
the RFC seems like it would rapidly become unwieldy for classes with a
large number of properties.Regards,
- Fred
On Aug 8, 2016, at 3:31 AM, Silvio Marijić marijic.silvio@gmail.com
wrote:Hi,
I would need your help with one idea. I'm working on one RFC that I'm
would
like to submit. Idea is that after you initialize object eg. after
constructor returns, object would be locked, and you wouldn't be able to
change properties on that object anymore. It would like this:<?php
immutable class Email {
public $email; public function __construct($email){ $this->email = $email; }
}
$email = new Email("example@email.com");After instance of class is created, object is "frozen" so call like this
$email->email = "new@email.com";
Would result in error.
I have already implementation up to certain degree, but I need one advice
from more experienced developers. Where is the place where I could put
logic to lock object after the constructor has finished? Maybe in zend vm
on ZEND_NEW token?Some constraints are needed:
- Child class that extends immutable class must be defined as immutable
also.- If property on immutable class contains object, it must be instance
of immutable class.- You can not have immutability per property, it either whole class or
none.Thank you all in advance.
--
Silvio Marijić
Software Engineer
2e Systems--
Silvio Marijić
Software Engineer
2e Systems
--
Silvio Marijić
Software Engineer
2e Systems
It will be patched before this RFC goes into official discussion.
That explains why all the rewritten tests I provided for Reflection fail:
https://github.com/brzuchal/php-src/pull/1
Should I create this PR against another repository? I created it against
the one that was last posted for review but no clue which would be right
one to contribute here?!?
--
Richard "Fleshgrinder" Fussenegger
@Fleshgrinder,
Well since implementation is still underway I think the best ways would be
to wait untill we finish implementation, and then we all can do the review
to make sure everything is in place.
2016-09-09 23:16 GMT+02:00 Fleshgrinder php@fleshgrinder.com:
It will be patched before this RFC goes into official discussion.
That explains why all the rewritten tests I provided for Reflection fail:
https://github.com/brzuchal/php-src/pull/1
Should I create this PR against another repository? I created it against
the one that was last posted for review but no clue which would be right
one to contribute here?!?--
Richard "Fleshgrinder" Fussenegger
--
Silvio Marijić
Software Engineer
2e Systems