Needs work
Project:
Drupal core
Version:
main
Component:
views.module
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
18 Apr 2022 at 20:00 UTC
Updated:
20 Jun 2025 at 16:10 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
neclimdulThe simple fix is to add the
attributeannotation.I actually found this though because ResultRow can become fairly unusable in twig because properties get really weird names that aren't parse-able by twig. Twig provides a workaround but it clearly discouraging the behavior and looks like this
{% set date = attribute(row, 'entity:node/field_publish_date') %}. It seems like it would make sense to have a real API with useful methods.Comment #3
mondrakeComment #4
neclimdulComment #5
andypostas there's no fixed list of properties which could be accepted the workaround looks better
should be enough
Comment #6
andypostComment #7
andypostFiled coder's issue to allow skip attributes introduced in newer PHP version #3292573: Allow parse/ignore native attributes
Comment #8
andypostUpstream issue for the attribute is https://github.com/squizlabs/PHP_CodeSniffer/issues/3489
Basically it can't be used on earlier PHP version but upstream should care about it instead of coder
Comment #9
andypostLooks related to https://github.com/phpstan/phpstan/issues/7345
Comment #10
andypostComment #11
andypostPHP 8.2 alpha3 container added, queued CI run for annotation https://www.drupal.org/pift-ci-job/2420836
Comment #12
andypostphpstan fails https://www.drupal.org/pift-ci-job/2420734 so disabled it for testing purpose
Comment #13
andypost@neclimdul at least the test from IS passed now on 8.3-alpha3 image https://dispatcher.drupalci.org/job/drupal_patches/136695/testReport/Vie...
Comment #14
andypostanother attempt to ignore
Extensionclass noise as log file > 500MBComment #15
andypostusing patched version of phpstan helped (need to wait for 1.8.1 version)
Comment #16
andypostComment #17
andypostBack review as attribute patch passed
Comment #18
andypostTests still fail on timeout because we needs newer vfs package
Comment #19
berdir#3299853: Apply #[\AllowDynamicProperties] attribute to base classes to make PHP 8.2 log size sane went in with this change, so this could be repurposed to actually provide a replacement API.
> Twig provides a workaround but it clearly discouraging the behavior and looks like this {% set date = attribute(row, 'entity:node/field_publish_date') %}
Fwiw, that is a search api specific thing, that will never happen with SQL queries/"standard" views. But I guess it can't be changed now, at least search_api would need to provide both the old and a normalized key for BC.
Comment #20
borisson_Does that make this change from a bug needed for 8.2 compatiblity to a task about code cleanup?
Comment #21
berdirIt's no longer a PHP 8.2 blocker, yes, maybe the initial problem about especially search_api identifiers being very hard to use in twig could still be a bug? But personally I'm fine to change it to change it to a task.
Comment #22
andypostnow it needs real-api to remove attribute
Comment #23
neclimdulSomething like this? Interdiff against the old api patch. Adds typing and update docs we can use in 10 as well as a full unit test.
Comment #24
andypostSomehow it falls to pass
Comment #25
neclimdulI suspect its this code in ViewResultAssertionTrait::assertIdenticalResultsetHelper
I assume this is using property_exists so it can detect properties that are null but it can't detect magic properties like this using to provide BC. Not sure the best way to handle this but we can probably just do something in the assertion if we're clever.
Comment #26
andypostre-parented to #3299855: [META] Get rid of #[\AllowDynamicProperties] attribute
Comment #27
andypostLooks tests are pass now!
I think we still need BC for contrib and custom code but it could use follow-up for 11.x
Comment #28
andypostHere's a patch to get current baseline for failed tests
Comment #29
andypostLocally all tests passed so checking idea from #25
Comment #30
andypostNo it has no effect except newly added test
Comment #31
andypost@neclimdul any idea how to move with it?
Comment #32
andypostlet's see this way
Comment #33
andypostFix one test and ensure NULL processed via
array_key_exists()Comment #34
andypostFix CS
Comment #35
smustgrave commentedSeems #34 had some failures.
Comment #36
mondrakeI'll give a try to this. In fact, this issue would be the major blocker for #3345938: Deprecate support for unused \PDO::FETCH_* modes. There, I'll be trying to remove usage of \PDO::FETCH_CLASS fetch mode. That mode is in fact a bit in contraddiction with the philosophy of PHP 8.2 that started tightening on usage of dynamic properties.
Comment #37
mondrakeComment #38
mondrakeComment #39
mondrakeComment #40
andypost@mondrake please elaborate why you're using
stdClassinstead of keyed array?I know that this bade class allows dynamic properties but array memory usage os lowed comparing to dynamic class properties
Comment #41
mondrakeComment #42
mondrake@andypost just because of this
my motivation here is (#36)
To me it doesn't matter array or stdClass - however I see the memory usage difference negligible.
Comment #43
mondrakeFor the record, the RFC says about stdClass and deprecation of dynamic properties
https://wiki.php.net/rfc/deprecate_dynamic_properties
Comment #44
mondrakeIMHO, we should postpone implementation of an API to access the row’s column values to a follow up.
Here we’re introducing usage of a storage class and magic methods to avoid dynamic properties, and it’s a full scope on its own. With this done, an API should start from deprecating the use of the magic methods.
Comment #45
mondrakeAdded tests for the magic methods.
Comment #46
mondrakeComment #47
alexpottThis doesn't really feel like much of a win. It feels like we're just doing this because we have `#[\AllowDynamicProperties]`. We're still ending up with a class with dynamic properties. Why not make ResultRow extend from \stdClass? And then I think we can drop the `#[\AllowDynamicProperties]` and have no other new code?
Comment #48
berdirI would definitely prefer making data an array and I don't see a problem with having arbitrary keys in there. That's by design and common, content entities also have an internal $values array property. A property typed on stdClass feels weird to me.
Comment #49
mondrake#47
1. that would not be sufficient to get rid of the
#[\AllowDynamicProperties]attribute, see the discussion part in https://wiki.php.net/rfc/deprecate_dynamic_properties#:~:text=Discussion...2. my motivation is #36, I would like to have a separate storage here, not added properties. No problem to switch back to array per #48.
Comment #50
mondrakeOn this.
Comment #51
alexpottFWIW @mondrake extending \stdClass would allow us to remove the attribute - see https://3v4l.org/qalMV#v8.2.3
Comment #52
alexpottI wonder about the performance implications of moving to an array and away from dynamic properties on the class. PHP will have double the number of things to track. I.e. instead on 1 object you'll now have an object and an array.
Comment #53
mondrake@alexpott thanks for #51 - I then misinterpreted the RFC.
#49.1 does not stand then, edited.
Comment #55
mondrakeChange to MR workflow. Just #46 applied to the MR.
Comment #56
mondrakeChanged stdClass to array.
Comment #57
daffie commentedAll the code changes look good to me.
The
#[\AllowDynamicProperties]has been removed from the class.Testing has been added.
For me it is RTBC.
Comment #58
berdirThis gets rid of the attribute but doesn't really address #2.
I don't quite understand why this adds hasColumn() but no other explicit methods to access the data. either we add get as well or we don't have has either? __isset() exists too? Ah, I I see, it's to replace the property exists check. Unsure about the name too.
I don't think moving to an array from undefined properties is a performance problem, if we're concerned about that then we should probably not rely on magic methods. array_key_exists() is also slower than isset(), if we're concened about performance?
Comment #59
mondrake#58 for sure if someone wants to develop a full fledged API according to #2, they may do so. In any case the magic methods will have to stay (even though deprecated) till next major. I think the point is more whether to do it here or in a following issue.
My motivation here is #36, I will not pursue any of the above further.
Comment #60
alexpottWe're changing from
if (property_exists($row, $this->aliases[$column])) {toif ($row->hasColumn($this->aliases[$column])) {- any contrib code that does this will break. As pointed out earlier dynamic properties on \stdClass are not deprecated so we're not really making a change we have to make here. So looking at contrib we'll break things see https://git.drupalcode.org/search?group_id=2&repository_ref=&scope=blobs... - plus if people are doing it in contrib then it will be done in custom code too.Comment #62
smustgrave commentedThis came up as a daily BSI target.
IS needs to be updated with the proposed solution.
MR needs to be opened for 11.x and address the open threads from 3588
Thanks!