-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[Bug] 65672 - Allow DatePeriod extensions to have writable properties #3121
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
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--TEST-- | ||
DatePeriod: Test read only properties | ||
--INI-- | ||
date.timezone=UTC | ||
--FILE-- | ||
<?php | ||
|
||
$start = new DateTime; | ||
$interval = new DateInterval('P1D'); | ||
$end = new DateTime; | ||
$period = new DatePeriod($start, $interval, $end); | ||
|
||
echo "recurrences: "; | ||
var_dump($period->recurrences); | ||
|
||
echo "include_start_date: "; | ||
var_dump($period->include_start_date); | ||
|
||
echo "start: "; | ||
var_dump($period->start == $start); | ||
|
||
echo "current: "; | ||
var_dump($period->current); | ||
|
||
echo "end: "; | ||
var_dump($period->end == $end); | ||
|
||
echo "interval: "; | ||
var_dump($period->interval == $interval); | ||
?> | ||
--EXPECT-- | ||
recurrences: int(1) | ||
include_start_date: bool(true) | ||
start: bool(true) | ||
current: NULL | ||
end: bool(true) | ||
interval: bool(true) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--TEST-- | ||
DatePeriod: Test cannot modify read only properties | ||
--INI-- | ||
date.timezone=UTC | ||
--FILE-- | ||
<?php | ||
|
||
$period = new DatePeriod(new DateTime, new DateInterval('P1D'), new DateTime); | ||
|
||
$properties = [ | ||
"recurrences", | ||
"include_start_date", | ||
"start", | ||
"current", | ||
"end", | ||
"interval", | ||
]; | ||
|
||
foreach ($properties as $property) { | ||
try { | ||
$period->$property = "new"; | ||
} catch (Error $e) { | ||
echo $e->getMessage() . "\n"; | ||
} | ||
|
||
try { | ||
$period->$property[] = "extra"; | ||
} catch (Error $e) { | ||
echo $e->getMessage() . "\n"; | ||
} | ||
} | ||
|
||
?> | ||
--EXPECT-- | ||
Writing to DatePeriod->recurrences is unsupported | ||
Retrieval of DatePeriod->recurrences for modification is unsupported | ||
Writing to DatePeriod->include_start_date is unsupported | ||
Retrieval of DatePeriod->include_start_date for modification is unsupported | ||
Writing to DatePeriod->start is unsupported | ||
Retrieval of DatePeriod->start for modification is unsupported | ||
Writing to DatePeriod->current is unsupported | ||
Retrieval of DatePeriod->current for modification is unsupported | ||
Writing to DatePeriod->end is unsupported | ||
Retrieval of DatePeriod->end for modification is unsupported | ||
Writing to DatePeriod->interval is unsupported | ||
Retrieval of DatePeriod->interval for modification is unsupported |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
--TEST-- | ||
Test for bug #65672: Broken classes inherited from DatePeriod | ||
--INI-- | ||
date.timezone=UTC | ||
--FILE-- | ||
<?php | ||
|
||
$interval = new DateInterval('P1D'); | ||
$period = new class(new DateTime, $interval, new DateTime) extends DatePeriod { | ||
public $extra = "stuff"; | ||
}; | ||
|
||
var_dump($period->extra); | ||
$period->extra = "modified"; | ||
var_dump($period->extra); | ||
|
||
# Ensure we can modify properties (retrieve for write) | ||
$period->extra = []; | ||
$period->extra[] = "array"; | ||
var_dump($period->extra); | ||
|
||
var_dump(isset($period->dynamic1)); | ||
$period->dynamic1 = "dynamic"; | ||
var_dump($period->dynamic1); | ||
|
||
# Ensure we can modify properties (retrieve for write) | ||
$period->dynamic2 = []; | ||
$period->dynamic2[] = "array"; | ||
var_dump($period->dynamic2); | ||
|
||
?> | ||
--EXPECT-- | ||
string(5) "stuff" | ||
string(8) "modified" | ||
array(1) { | ||
[0]=> | ||
string(5) "array" | ||
} | ||
bool(false) | ||
string(7) "dynamic" | ||
array(1) { | ||
[0]=> | ||
string(5) "array" | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.