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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:18:52+00:00 2026-05-30T08:18:52+00:00

Please explain me why that code: class kategoria { public $IdKat; public $NazwaKat; public

  • 0

Please explain me why that code:

    class kategoria
    {
        public $IdKat;
        public $NazwaKat;
        public $OpisKat;
    }

    class dbClass  
    {  
        private $link;

        private $user = USER;
        private $pass = PASS;
        private $database = DATABASE;



        function __construct()  
        {  
            try
            {
                $this->link = new mysqli('localhost', $this->user, $this->pass, $this->database);  
                $this->link->set_charset('utf8');
            ;
            }
            catch(Exception $exc)
            {
                echo $e;
            }
        }  


        function get_cats()  
        {  

            $query = "SELECT IdKat, NazwaKat, OpisKat  FROM `kategorie`"; 

            try
            {
                $stmt = $this->link->prepare($query);

                /* bind parameters for markers */
                //$stmt->bind_param("i", $IdKat);

                $stmt->execute();
                $kat = new kategoria();

                $stmt->bind_result(
                        $kat->IdKat, 
                        $kat->NazwaKat, 
                        $kat->OpisKat
                        );


                $output = array();
                $output2 = array();

                while ($stmt->fetch()) {

                    array_push($output, $kat->IdKat);
                    array_push($output2, $kat);
                    // array_push($output2, clone $kat); // i tried cloning like this
                    // $output2 += array(clone($kat)); // tried adding
                }

                $stmt->close();
            }
            catch (Exception $e)
            {
                echo $e;
            }

            echo '<pre>';
            print_r($output);
            echo '</pre>';
            echo '--------------------------<br/>';

            echo '<pre>';
            print_r($output2);
            echo '</pre>';
        }  

    }  

Gives me data like this:

Array (
    [0] => 2
    [1] => 3
    [2] => 4 )

--------------------------

Array (
 [0] => kategoria Object
     (
         [IdKat] => 4
         [NazwaKat] => Hi-Fi
         [OpisKat] => Music equipment
     )

 [1] => kategoria Object
     (
         [IdKat] => 4
         [NazwaKat] => Hi-Fi
         [OpisKat] => Music equipment
     )

 [2] => kategoria Object
     (
         [IdKat] => 4
         [NazwaKat] => Hi-Fi
         [OpisKat] => Music equipment
     )

 )

This is my second question about it. I tried adding arrays, cloning object $kat and it didnt worked. Finally i made another array and im using both for debugging.

It looks weird. I dont understand why cloned object in array is overwriten after next row fetching. It supposed be a copy of his clone, right?

  • 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-05-30T08:18:53+00:00Added an answer on May 30, 2026 at 8:18 am

    I found answer in PHP help. I had to create “deep copy” like this:

    $clone = unserialize(serialize($object)); 
    

    Because (i believe) help says: “Any properties that are references to other variables, will remain references.”

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

Sidebar

Related Questions

Please explain what this task is about? Create a generic linked list class that
Please explain why this test passes? [Test] public void TestNullOps() { Assert.That(10 / null,
Can someone please explain how you can write a url pattern and view that
Based on Please explain JSONP , I understand that JSONP can be used to
This is the sample code : public class OverloadingExample { public void display(Object obj){
I know that the below code is a partial specialization of a class: template
Please explain the technique used in this code to test Object Equality and Identity.
could some one please explain this snippet of magento code found in loadByCustomerId() in
Sorry for big chunk of code, I couldn't explain that with less.Basically I'm trying
Can some one please explain to me why this piece of code prints out

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.