Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9308253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T00:35:12+00:00 2026-06-19T00:35:12+00:00

Ok i got a weird issue here. Im trying to calculate the old date

  • 0

Ok i got a weird issue here.
Im trying to calculate the old date and the new date. However i spotted a issue that is unexplainable by me.

The setup :
I have 2 new dates set on today.

$tempstamp = new DateTime();
$newstamp = new DateTime();

Now, i edit the newstamp into a new date useing :

if ($newstamp ->format('His') > 120000) $newstamp ->modify('+7 day');
else $newstamp ->modify('+4 day');

Which works perfectly. However now comes the weird part.
When i dump both values before and after it the tempstamp gives a unexplainable value :

case '2':
  $tempstamp = $newstamp;

  dump($tempstamp->format('m-d')); // 02-19 - CORRECT
  dump($newstamp->format('m-d')); // 02-19 - CORRECT

  if ($newstamp->format('His') > 120000) $newstamp->modify('+7 day');
  else $newstamp->modify('+4 day');

  dump($tempstamp->format('m-d')); // 02-26 - FALSE
  dump($newstamp->format('m-d')); // 02-26 - CORRECT

*NOTE: dump is our way of var_dumping*

The Question:
Can someone explain why tempstamp is getting editted as well while i only edit newstamp?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T00:35:13+00:00Added an answer on June 19, 2026 at 12:35 am

    PHP copies objects by reference, not by value. So $tempstamp = $newstamp; is now making $tempstamp and $newstamp point to the same object. To avoid this you need to use clone:

    $tempstamp = clone $newstamp;

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey, I got kind of a weird issue here. I have an iPhone-only OpenGL
I'm running a weird issue here. I have code that makes jquery ajax calls
I got a bit of a weird issue here. (Either that, or I'm just
I've got a weird issue that almost seems like a Visual Studio 2008 issue.
I have got one weird issue. I am working on an asp .net mvc
I've got a weird issue with segues - I have a segue open a
I seem to have some weird issue going on that I am sure will
I got a weird issue. I hope someone could help me. I am new
Got this weird issue with Using jQuery 1.6.0 issue. I am trying to append
I'm running into a weird issue that I've never noticed before. I have the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.