instantiating one class in another class...

Problems with the Windows version of XAMPP, questions, comments, and anything related.

instantiating one class in another class...

Postby hem » 23. June 2009 07:15

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...
hem
 
Posts: 7
Joined: 18. June 2009 13:08

Re: instantiating one class in another class...

Postby Wiedmann » 23. June 2009 07:29

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"?
Wiedmann
AF Moderator
 
Posts: 17106
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Re: instantiating one class in another class...

Postby hem » 23. June 2009 08:19

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..
hem
 
Posts: 7
Joined: 18. June 2009 13:08

Re: instantiating one class in another class...

Postby Wiedmann » 23. June 2009 08:32

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
Wiedmann
AF Moderator
 
Posts: 17106
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 62 guests