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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:10:03+00:00 2026-06-16T05:10:03+00:00

I have a class a and instantiated it using new $obja = new a;

  • 0

I have a class a and instantiated it using new

$obja = new a;

I know the difference between the below two lines

$obja2 = $ojba;
$obja2 = clone $obja;

But even if you declare or not declare __clone in the class a the first line $obja2 refer to $obja memory space and second line creates a copy of the $obja. Till here it is clear to me.

Then why php is having a magic method __clone?
Is it only for executing a set of codes which is written inside __clone while we use $obja2 = clone $obja;

Somebody please help to get a better idea of it.

  • 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-16T05:10:05+00:00Added an answer on June 16, 2026 at 5:10 am
    void __clone ( void )
    

    Once the cloning is complete, if a __clone() method is defined, then
    the newly created object’s __clone() method will be called, to allow
    any necessary properties that need to be changed.

    http://php.net/manual/en/language.oop5.cloning.php#object.clone

    So yes, it’s a callback after the clone operation has finished. Nothing more, nothing less.

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

Sidebar

Related Questions

I have a class that is a singleton. This singleton is instantiated using GCD
I have a Class A that when it is instantiated and saved for the
Suppose that we have previously instantiated three objects A, B, C from class D
I have a class that instantiates two classes which implement interfaces. I want one
I have a class that I am creating within an AppDomain using CreateInstanceAndUnwrap. The
I have written the code shown below: public class SiteMapFactory { public static ISiteMap
I know that the Socket class can be instantiated in this way (as an
Nearly all my controllers have a repository instantiated by initializer like this: public class
I have a base recipe class and I am using a datacontext. I overrode
I have a class that I instantiate to save or load xml data. For

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.