Comments (13)
+1, would love to see this -- remembering to chain ->copy() all the time is pretty annoying/frustrating
from carbon.
Anything that modifies the internal state should return a new instance.
<?php
public function modify($mod)
{
$instance = clone $this;
$instance->modify($mod);
return $instance;
}
from carbon.
Correct. There are no immediate plans to change this. However, I don't think it would take too much to create a subclass that used a copy on write strategy for mutating function calls.
from carbon.
I agree with @beberlei, the fact that DateTime
is mutable is very annoying.
Please consider making this immutable.
from carbon.
So would a copy on write implementation fit the bill? Thoughts?
from carbon.
Yes, I get that.. hence the copy on write implementation comment. Is that what you guys are looking for?
from carbon.
I agree, this behaviour is annoying, but wouldn't it break BC? What about a copy()
method to allow chaining?
<?php
# Hmm, no pun intended here...
$carbon->copy()->modify("midnight");
Perhaps the copy on write implementation should wait for a BC breaking v2.0.0?
from carbon.
Meh, never mind. It already exists... :x
from carbon.
No further action here... going to close it for now.
from carbon.
Someone tried to fix it in php 5.5: http://www.php.net/manual/en/class.datetimeimmutable.php , but not without issues http://comments.gmane.org/gmane.comp.php.devel/78803
from carbon.
Its not high on my list right now. As I have said though, I think a copy on write implementation would be pretty quick.
from carbon.
@falk the issues of the mailing list were completly fixed, 5.5 has an immutable date time that works flawlessly.
from carbon.
+1, this just bit us today at work. Side-effects suck and make Carbon more difficult to use as a value object.
from carbon.
Related Issues (20)
- Carbon v3 Documentaion for diffIn* methods HOT 2
- More granular v2 to v3 upgrade documentation? HOT 3
- [Translation tool] bs HOT 2
- diffForHumans() gives incorrect wording for SLOVAK language HOT 1
- Type error when calling canBeCreatedFromFormat with null date HOT 3
- diffInDays returns a float HOT 7
- Not working after download zip file HOT 1
- Serialization of 'Closure' is not allowed HOT 2
- Invalid CarbonInterval->format() results for Carbon 3 (unknown). HOT 8
- It is not possibble to upgrade Symfony 6.4 to 7.0 without upgrading Carbon from 2 to 3 HOT 1
- Carbon::now after Carbon::setTestNow gives incorrect results HOT 1
- Please don't modify existing instances with date arithmetic methods HOT 1
- Unknown or bad timezone (:/etc/localtime) HOT 2
- Carbon::createFromFormat Incorrect Month Output for February HOT 1
- Error parsing date HOT 1
- Unserialize from Carbon v2 objects HOT 1
- Carbon createFromTimestampMs no default time zone if it is set in env variable of Laravel app HOT 1
- `CarbonInterval`'s `days` property return false HOT 2
- [Translation tool] sr_RS@latin
- Date difference problem HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from carbon.