Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] 65672 - Allow DatePeriod extensions to have writable properties #3121

Closed
wants to merge 3 commits into from

Conversation

duncan3dc
Copy link
Member

@duncan3dc duncan3dc commented Feb 17, 2018

It looks like the properties were prevented from being writable as part of a serialization fix: 0ee7155

However there are no tests for this, so it seems it may have been unintentional. Also a bug was opened and hasn't been marked as "not a bug" so this PR restores the previous functionality, and includes tests for it.

@derickr
Copy link
Member

derickr commented Feb 19, 2018

Can this be used to write to DatePeriod native properties?

@duncan3dc
Copy link
Member Author

According to the docs there aren't any public properties on the class, unless I've missed something?

ext/date/php_date.c Outdated Show resolved Hide resolved
@nikic
Copy link
Member

nikic commented Feb 19, 2018

As we now use delayed wakeup in unserialization the original reason for preventing writes to properties has gone away, so this LGTM.

@cmb69
Copy link
Member

cmb69 commented Feb 20, 2018

According to the docs there aren't any public properties on the class, unless I've missed something?

var_dump((new DatePeriod(new DateTime('now'), new DateInterval('P1D'), new DateTime('tomorrow')))->recurrences);

If it was possible to arbitrarily change these properties, I'd expect malfunctions.

@duncan3dc
Copy link
Member Author

Thanks for that Christoph, I'll take a look at ensuring any public properties are prevented from being updated and that we have tests for them. I'll also update the docs with any public properties I find

@duncan3dc
Copy link
Member Author

duncan3dc commented Feb 20, 2018

I've re-written this PR now, it changes the current functionality from preventing writes to any properties, to only prevent writes to native properties.

I've also added tests to ensure native properties can be read, to ensure they can't be written, and to ensure custom properties can be read and written.

I've also submit a documentation patch via the Docbook Online Editor to list these public properties

@imbrish
Copy link

imbrish commented May 23, 2018

@derickr @nikic any progress on this one?

@derickr
Copy link
Member

derickr commented Jun 5, 2018

I only had a question about functionality. I didn't look at the patch or implementation, so I defer to @nikic — however, Travis tests show failed for this PR.

@duncan3dc
Copy link
Member Author

@derickr I believe the travis issue is a memory leak that was already present before this PR, and it looks like it has since been resolved by @nikic in b72b1a4

Should this PR target master/7.3 instead? Or is there a workaround for this memory leak we can apply to 7.1?

@duncan3dc duncan3dc changed the base branch from PHP-7.1 to PHP-7.3 February 10, 2019 23:02
@duncan3dc
Copy link
Member Author

I've rebased this against 7.3 to take advantage of the memory leak fix.
Travis shows ENABLE_MAINTAINER_ZTS=0 ENABLE_DEBUG=0 as passing, but the ENABLE_MAINTAINER_ZTS=1 ENABLE_DEBUG=1 build is still showing a memory leak (https://travis-ci.org/php/php-src/jobs/491390023).
Should I raise a bug for this separate issue?

php-pulls pushed a commit that referenced this pull request Feb 12, 2019
get_properties() constructs these as fresh objects with no relation
to the internals, there is no need to clone them again. Additionally
the current implementation leaks memory, because the original objects
are never freed (see PR #3121).
@nikic
Copy link
Member

nikic commented Feb 12, 2019

@duncan3dc I've fixed the leak in a109fdd, please rebase again.

ext/date/php_date.c Outdated Show resolved Hide resolved
@duncan3dc duncan3dc changed the base branch from PHP-7.3 to PHP-7.2 April 28, 2019 20:57
@nikic nikic self-requested a review April 28, 2019 21:23
ext/date/php_date.c Outdated Show resolved Hide resolved
@nikic
Copy link
Member

nikic commented Apr 29, 2019

You'll also want to make similar modifications to date_period_read_property. The thing to test would be operations like $period->someArray[] = 123.

@duncan3dc
Copy link
Member Author

@nikic Thanks for the help, I've updated now to handle the string properly, and ensure reading for modification is handled the same way

Copy link
Member

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Please be careful when merging up, I think in 7.4 you may need to change tests due to DateInterval comparison and in master you'll have to change the object handler signatures.

ext/date/php_date.c Outdated Show resolved Hide resolved
@nikic
Copy link
Member

nikic commented May 21, 2019

Do I remember right that you have php-src karma? If not, I can commit this change for you.

@duncan3dc
Copy link
Member Author

@nikic I do, let me refactor those repeated property checks first though.
I'm on vacation this week, but I'll take a look next week then ping you for a final review.

Unless you'd prefer to get this merged sooner, in which case I'm happy for you to go ahead 👍

Although these properties are not currently documented,
they've been publically available so we should ensure they remain so
@duncan3dc
Copy link
Member Author

I noticed an issue on PHP-7.4 while merging up, I've opened #4198 to demonstrate. I presume we'll want to get that resolved first before committing this change

@duncan3dc
Copy link
Member Author

Committed as dc586bf and 8b53c72

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants