SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Talk to the /dev/null Theiggsta's Avatar
    Join Date
    Mar 2001
    Location
    Tampa, FL
    Posts
    376
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Object and Class Question

    Is there ANY way I can call an obect from another object?

    PHP Code:
    class foo {
    function 
    bar() {
    //stuff
    }
    }

    class 
    bar {
    function 
    foo() {
    $test->bar()
    }
    }

    $test = new foo;
    $testb = new bar;

    $testb->foo(); 
    Now thats really really crude, but thats the basic idea im goin for. I want to be able to call on another active object from another object if at all possible.
    Last edited by Theiggsta; Jun 9, 2001 at 09:25.
    Aaron "Theiggsta" Kalin
    Pixel Martini
    Ruby and Rails Developer

  2. #2
    Talk to the /dev/null Theiggsta's Avatar
    Join Date
    Mar 2001
    Location
    Tampa, FL
    Posts
    376
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Aparently this works...

    PHP Code:
    <?
    class foo {
        function 
    test() {
            return 
    15;
        }
    }

    class 
    bar {
        function 
    testr() {
            global 
    $test;
            return 
    $test->test();
        }
    }

    $test = new foo;
    $testb = new bar;

    echo 
    $testb->testr();
    ?>
    shows 15

    So I guess that calls it, but is there any other way? just curious...
    Aaron "Theiggsta" Kalin
    Pixel Martini
    Ruby and Rails Developer

  3. #3
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    This would typically be the way that would be written in an object oriented language:
    PHP Code:
    <?php
    class foo {
        function 
    test() {
            return 
    15;
        }
    }

    class 
    bar {
        function 
    testr($foo_object) {
            return 
    $foo_object->test();
        }
    }

    $test = new foo;
    $testb = new bar;

    echo 
    $testb->testr($test);
    ?>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •