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 8508491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:10:36+00:00 2026-06-11T03:10:36+00:00

There are two objects of the same class: $obj1 = new MyClass(); $obj2 =

  • 0

There are two objects of the same class:

$obj1 = new MyClass();
$obj2 = new MyClass();

Then I applied a function func to $obj2. However, once this function is executed, I noticed that the content of $obj1 has magically changed as well. I do not use any reference to $obj1 inside func. What might be the possible reasons of this problem? How do I solve it?

$obj2 = func($obj2,$vars);

I should say that I use other functions before func, and they also use $obj2 as an input. However, after their execution the content of $obj1 get not changed.

P.S. When I debug this code in Zend Studio and go inside func, Watch list Expressions says that $obj1 = null, but I think it’s fine, because func is saved in a different PHP file.

  • 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-11T03:10:37+00:00Added an answer on June 11, 2026 at 3:10 am

    Consider this:

    class MyClass
    {
      public static $value;
    
      public function test( $testvalue )
      {
        self::value = $testvalue;
      }
    }
    
    $obj1 = new MyClass();
    $obj2 = new MyClass();
    
    $obj1->test( 123 );
    
    echo $obj2::value; // this will echo 123!!
    

    There are no changes to made to $obj2, only to $obj1. The static causes the var to loose its object contents, and becomes ‘global’ to all objects.

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

Sidebar

Related Questions

let's suppose there are two objects of class abc abc obj = new abc(10,20);
On iOS, if there are two circles, both of which are UIView objects, then
I have the following two Vector objects in java. Vector<SomeClass> obj1; Vector<SomeClass> obj2; The
There are two objects. The Windows Form with a button and a progress bar,
Say there are two objects, A and B , and there is a pointer
Is there a way to get distance between two objects in meters? I'm trying
I'd like to know whether there is a way to compare two objects in
I need a library to handle JSON objects in Ruby. There are two gems
What VB6 method allows two custom objects of the same type (defined in a
I have two objects of the same type and need to copy property values

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.