Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Location
    The Netherlands
    Posts
    252
    Thanks
    0
    Thanked 0 Times in 0 Posts

    extending classes

    Hi,

    I'm currently working on a script that has multiple layers (common, business and gui). In my index.php I include the three diffent files each with there own class. What I now would like to do is call to some function of the commonlayer in the business layer and the gui layer. Is it possible to do this directly? Or are there any other ways? Please provide a short code-snippet, for I'm new at this stuff!

    Thanx Michiel

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    577
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ClassName::functionName() would invoke the function of the named class though wouldn't instantiate an object of the class - you could pass the object or object part through the function call if really needed.

    if your function simply take a parameter (object or value) and return a manipulated version or somesuch then you'd only need to call something like

    $this->return_array = OtherClass::arrayFunction($this->my_array);

    If you had extended the base class you could also use parent::function() to call ummm functions within the ummm parent class

    I would suggest seeking a few articles on classes and passing objects between classes - maybe also look at phppatterns.com or the advanced php sections at devnetwork.net or sitepoint
    Ökii - formerly pootergeist
    teckis - take your time and it'll save you time.

  • #3
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,058
    Thanks
    10
    Thanked 96 Times in 94 Posts
    you could also aggregate your classes ...

    PHP Code:
    <?php
    class uber{
        function 
    uber(){
           
    $this->common = &new common() ;
           
    $this->business= &new business() ;
           
    $this->gui= &new gui() ;
        }
         
        function 
    whatever(){
            
    $this->gui->build($this->common->results);
        }
    }
    ?>
    there are names and rules for these methodologies , as Okii suggests phppatterns is an excellent resource.

    Having said that I for one am very anti 'lets clone JAVA' when it comes to design patterns as I don't personally see the case for it , but its good reading nonetheless.


    you can also use .. $this->parent() to instansiate the parent class ... eg

    PHP Code:
    <?php
    class foo{
        function 
    foo(){
            
    $this->yak 'dude';
        }
        function 
    yak(){
            return 
    $this->yak ;
        }
    }

    class 
    bar extends foo{
       function 
    bar(){
            
    $this->foo();
            echo 
    $this->yak();
       }
    }

    $bar = new bar();
    ?>
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)


  •  

    Posting Permissions

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