1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Rep Power

    Creating objects inside other objects.

    Hi all

    Is it possible to create and use objects from inside other objects' functions in php. I'm using version 4.3.3, and either I'm doing something stupid (highly likely) or you can't do it. I have one fairly large class and inside one of its functions I create another object. Now, this new object has a function which takes a bunch of parameters to set up the object (didn't do it in the constructor for other reasons), after which I pass the object to yet another object which has been created in the same function. However, after setting up the first object, all of its values are empty. How can this be? Heres some code to explain it better.

    $result = new CResults();
    $reportGen = new CReportGenerator();

    $this->arrManagers [$matchNum]["Manager1"],
    $this->arrManagers [$matchNum]["Manager2"],
    $reportGen->GenerateReport ($result);

    Remember that all of this happens inside another class. The GenerateReport function is declared like this:

    function GenerateReport (&$results)

    so its not a pass by reference problem. Even if I print any of the variables in the CResults class after calling PopulateResults, they're all empty? Anybody have any insight?

  2. #2
  3. coding with style
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2003
    Rep Power
    If you want to know if PHP can do something, test it!

    PHP Code:

    class test2 {
    print_stuff($stuff) {

    test {
    create_class() {
    $test2 = new test2;
    $test2->print_stuff("this is some stuff");

    $test = new test;

    - Nycto

IMN logo majestic logo threadwatch logo seochat tools logo