Page 1 of 1

instantiating one class in another class...

PostPosted: 23. June 2009 07:15
by hem
i have 2 class.
1st class--

Code: Select all
<?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;
    }
}
 
?>


2nd class---
Code: Select all
<?php

require_once("CloneDemo1.class.php");

class TestCloneDemo1

    $cloneObj1 = new CloneDemo1();

    $cloneObj1->setEmploeeId(15264);
    $cloneObj1->setTieColor("Black");


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

?>


now when i try to execute the second class i am getting the following error--
Parse error: parse error, expecting `T_FUNCTION' in F:\xampp\htdocs\Object\Cloning\phpdesigner_tmp24.php on line 20

Note- to import the first class i have also used include(); but getting the same error..

Thank u...

Re: instantiating one class in another class...

PostPosted: 23. June 2009 07:29
by Wiedmann
have 2 class.
Code: Select all
Parse error: parse error, expecting `T_FUNCTION' in F:\xampp\htdocs\Object\Cloning\phpdesigner_tmp24.php on line 20

Which of those both scripts is the file "phpdesigner_tmp24.php"?

Re: instantiating one class in another class...

PostPosted: 23. June 2009 08:19
by hem
This is that one--

Code: Select all
<?php


 /*function __autoload($class)
    {
        require_once ("classes/$class.class.php");
    }
*/

require_once("CloneDemo1.class.php");

class TestCloneDemo1
{

 
    $cloneObj1 = new CloneDemo1();

    $cloneObj1->setEmploeeId(15264);
    $cloneObj1->setTieColor("Black");


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


}

?>


but its ide generated one i think
i use phpdesigner 6.2 with xampp.
and my files are in htdocs in this style----

main folder = myp
inside myp = Object folder
inside Object folder = Cloning
and inside Cloning = all these above files..



NOTE-- if i keep all the files in one class, then its running quite well but only when i try to instantiate the first one from the second class i get that error.....Thank u..

Re: instantiating one class in another class...

PostPosted: 23. June 2009 08:32
by Wiedmann
2nd class---
...
This is that one--

Well, both scripts have the same error. You can't use PHP code in this way inside a class.
--> http://de.php.net/manual/en/language.oop5.basic.php