Jump to content

Recommended Posts

my problem is i have one class in a separate file. And i want to make an object of that class in another class which resides in a separate file. so the Question is how can i import the first class to the second class.

 

the first class name = CloneDemo1.php

and the second class name = TestCloneDemo1.php

I think you are trying to ask about "how do I include the files easily for multiple classes" for which I will respond:

 

http://nz.php.net/manual/en/language.oop5.autoload.php

 

Perhaps I am misunderstanding however with your use of file names and no class names.  People be more clear if this doesn't solve your problem.

"ya i want to know "how do I include the files easily for multiple classes"

i have one file like this--

 

<?php

 

class CloneDemo1

{

 

    private $employeeid;

    private $tiecolor;

 

 

    function setEmployeeId($empid)

    {

        $this->employeeid = $empid;

    }

 

    function getEmployeeId()

    {

        return $this->employeeid;

    }

 

    function setTieColor($tcolor)

    {

        $this->tiecolor = $tcolor;

    }

 

    function getTieColor()

    {

        return $this->tiecolor;

    }

}

 

and another one like this--

 

<?php

 

function __autoload($class)

    {

    require_once($CloneDemo1.class."php");

    }

 

 

class TestCloneDemo1

{

 

 

    $cloneObj1 = new CloneDemo1();

 

    $cloneObj1->setEmploeeId(15264);

    $cloneObj1->setTieColor("Black");

 

$cloneObj2 = clone $cloneObj1;

 

$cloneObj2->setTieColor("Navy Blue");

 

    printf("Employee id:%d<br />", $cloneObj1->getEmployeeId());

    printf("Employee tie color:%s<br />", $cloneObj1->getTieColor());

    printf("Employee tie color:%s<br />", $cloneObj2->getTieColor());

   

}

 

?>

 

Now i am getting some error like parse error T_FUNCTION etc... indicating the line whr i instantiate the object in the sencond class... Plz help me with exact code.... Thank u

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.