Good morning! Over the weekend I encountered a problem and thought if it warranted a new language feature. Sometimes you have an abstract class with several child implementations, and you want to keep the constructor free for children to implement it.
In other words: you don't want children having to call parent::__construct(). There are some cases though where you also want the abstract parent class to do some setup work which you don't want to bother the child classes with, in essence you'd want a method that's automatically called after an object was contructed (::__constructed ?)
This would of course be a quality-of-life feature for developers, and I know many people oppose to adding core functionality when it can easily be solved in userland. I'm also aware that magic methods are controversial, but they are still the only thing we have.
Though, from a package-maintainer point of view, it would add more flexibility. So I figured I might as well ask the question here. Maybe it's been discussed before?
Hey @BrentRoose: The problem I see is when I explicitly do not want the parent constructor to be called (for reasons) there is no way for me to hinder that. Or we would need a special way to explicitly skip calling this constructor-method.
Or I don't want to call the parents constructor method but the one of the parents parent.... (again: Reasons) IMO using this parent::__construct() makes it explicit that you also want to call the parents method. No magic involved...
@JoeWatkins shared PHP objects are hard to implement indeed ) Need to write a lot of code for low-level initialization of zval for properties, as they are GC-ed during symbol table cleanup procedure, also object->ce pointer is changing between first 2-3 requests, then class_entry became persistent. Property handlers should be reimplemented to perform copying zvals into persistent memory... So, give up that idea
@JoeWatkins Ended with PHP module and shared memory structure in module_entry.globals_ptr
@BrentRoose there is something similar hacklang is solving with attributes. first a Sealed Attribute that allows the parent class to enforce who clients are. second a ConsistentConstruct attribute that requires the signature of each constructor to be the same as parent class:
@NikiC will do, sorry for causing you work you could have let me the other one. is there a CI build that produces them? i didn't have leaks running with -m
In Xdebug 3, you'd need xdebug.mode=coverage for that to happen though, but that doesn't address the real issue either.
@JoeWatkins In the overridden handlers, I do return ZEND_USER_OPCODE_DISPATCH - I would have thought that by using the API set_user_opcode_handler it would have handled the chaining for me? I'm not sure how to dispatch to the previous handler.
yeah it doesn't do that, you have to do it manually exactly as you expected zend was doing it - have enough space for user_opcode_handler_t*n and before your call to set_user_opcode_handler in minit do get_user_opcode_handler and call it in place of return _DISPATCH where it's available ...
@NikiC ugg that memory leak you found is something i had in the back of my mind to check the early exits for and forgot bceause i didnt put it into the todolist :( sorry
@Sherif Well... you can't push to salathes currently... And the one on git.php.net get's updated every two hours from the SVN repo...
@salathe It's being updated every two hours from the SVN. So I'd say yes: it is ready for that ;-)
@salathe though the changes to use the git-based documentation are currently in a separate branch on the SVN. So those changes need a review IMO before they should be merged into master....
@JoeWatkins @LeviMorrison @salathe y'all voted no on this Attributes RFC by Dmitry in 2016, do you maybe still know the reason? wiki.php.net/rfc/attributes
@beberlei in the case where an attribute is code, what is passed to userland is an AST representation, which we don't have a good API for ... this makes processing an attribute as near as makes no difference as difficult as parsing out the AST from a doc comment yourself ...
making an execution engine (which is more or less what an AST evaluator is) built in userland a necessity if you want code in attributes made no sense then, and it's make little more sense today even with jit and other improvements in mind ...
not if that places the same restrictions on code attributes as constant expressions ... an expression ought to result in a function closed over the scope is was declared in when accessed from reflection
@lisachenko i think joe refers to something else here, nothing to do with caching parsed structures, dmitrys proposal made ast nodes available to userland, that required evaluation at runtime to make any use
@JoeWatkins so you mean not restriction, but "expansions" in a sense that constant ast expressions import global state?
@pmmaga It could be allowed if we wanted to change the interpretation of multiple use blocks entirely (i.e. make sure that there are no references to traits in other use blocks etc), but I don't think that's worth the bother.
And well, it would be a larger break, though I have no idea if anyone ever uses more than one use block
How to declare nullable property? The only thing I got to was only helper function to create typed property with long, string, etc. like zend_declare_property_string(semver_ce_ptr, "metadata", sizeof("metadata")-1, "", ZEND_ACC_PUBLIC); ??
In my SemverVersion class properties like major, minor or patch are always long, but from semver pov the metadata and prerelease are optional so I was thinking of declaring them as nullable string properties
Hi NiKic, I need your help for paid project, your help would be as guidance to implement a work. Kindly, can u share any way that can show u the project details. Thanks
Good morning sir, I has great opportunity for you that will change the life. Change is the world! Please send info for the contact so you be rich like a me.
@Ekin Tell @PeeHaa to create a youTube channel for his mixes so I can add them to my programming playlist. Seriously, listening to "Just Alone" again right now.
I am a nigerian prince but I have been forced on the run. I have 5,000 high quality php-src pull requests on my hard drive and need help transferring them so the government cannot take them. If you agree to send me your git.php.net private certificate we have a great opportunity for profit and I will allow you to claim credit for 20% of them.
@NikiC if i have a symbol "Foo" in the AST, when I resolve it with zend_resolve_class_name, does that only resolve classes or also "use const" and "use function" imports?
I wish totally portable software was easier, but until recently Windows almost seemed anti-open-source, so it wasn't a viable platform for people like me.
I've never had a problem with running open source on windows, for things designed for Windows. But of course if it's a toolkit for a completely foreign API then sure it wont work
@NikiC wondering if i could also resolve attribute names against constants and check they exist, otherwise error. then REflectionAttribute::getAsObject would throw in this case. could help with usecases where you only need to "tag" the declaration and requiring an extra class seems pointless
Unrelated point of order: I just miss-typed a URL into php.net and noticed it saying it was running NGINX 1.14 which is getting on 15 months old now, I think there's been a few CVEs patched since then too.
> It is possible to use the same attribute name more than once on the same declaration. This is one change to the previous Attributes RFC where this was not possible.
But it doesn't explain the behavior when this happens.
@LeviMorrison Reflection*::getAttributes() returns a list of ReflectionAttribute, each has getName(), which can occur multiple times. what you do with it is userland concern
I could reference the "Reflection" section where its explained
it is associated by name on the engine level, so that extensions can do a simple zend_hash_Str_exists() (explained a little lower in the Use Cases for Extensions section)
is getAttributes(string $name = null); not good "enough"? adding a second method seems overkill, the return value stays exactly the same. AttributeSet would bring nothing new to the table over a array list of things or?
i don't want to blow this up to have $n new things, it already has too much new things in reflection imho :)
@LeviMorrison i see nice use cases injecting \Tideways\Attribute\Instrumented during ast processing to tag functions and checking that in zend_execute or opcode handlers, not sure how much of this would still be needed after instrumentation API, also the use case of disabling jit for instrumented functions
@MarkR it solves the issue of typos in attributes and nothing happening, i agree though, this is probably the most controversial thing
i feel annotations is like the democratic primary, 6 contenders and in the end nobody gets to 66% :p
I'm missing something... I had to manually renew my LE cert on my VPS, I tried running one of my domains through ssl labs which is complaining that my server has TLS 1.0 and TLS 1.1 enabled, but in my nginx.conf file, I have ssl_protocols TLSv1.2;, what gives?
/me just went through about 5k lines of code... to find out where and how a single inherited prop that I have to work on was set... and it was all the way up in the inheritance tree
Surprised there is so much pushback against function/method/expression support for constants/parameters/etc. Seemed a pretty arbitrary distinction to me
I can just about get behind them being used for class constants, mainly because I think doing constant maths-like equations in constants would be fine. But in parameters I think it gives a different impression, almost as if it would run each time
@NikiC even still, I'd expect it to be a bit more even than it is
@MarkR it would run each time
> For parameter defaults, the proposed behavior would be that default expressions containing calls would get evaluated every time the parameter default was used.
yeah, why not let people shot themselve sin the foot, php has enough ways to do this, it is arbitrary to limit it in some places :) i agree nikis examples look so much more useful, especially the public $foo = new Foo(); is something needed
Something something, I don't want to look into that code base, something, docs would also be nice, something, but for how rarely I'm going to use it ...
I'm literally learning how pecl works by reading schema, looking at other exts, and running pecl commands. That's basically PHP's documentation philosophy: read the source, look at other works.