SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 27 of 27
  1. #26
    SitePoint Enthusiast
    Join Date
    Jul 2004
    Location
    Finland
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is actually one way how you can call common methods from multiple classes. It's bit of a hack but works, though I don't recommend to use it because it's not documented feature.

    PHP Code:
    class Common{
        protected 
    $property '';
            
        function 
    commonMethod(){
            
    $this->property 'test';    
        }

    }

    class 
    SomeClass{
            
        function 
    commonMethod(){
            
    Common::commonMethod();    
        }
        
    }

    class 
    SomeOtherClass{

        function 
    commonMethod(){
            
    Common::commonMethod();    
        }
    }

    $obj = new SomeClass();
    $obj->commonMethod();

    $obj2 = new SomeOtherClass();
    $obj2->commonMethod();

    /* output
    SomeClass Object
    (
        [property] => test
    )
    SomeOtherClass Object
    (
        [property] => test
    )
    */ 
    Interesting Just spotted this from http://fi2.php.net/manual/en/language.oop5.php

  2. #27
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is what dbevfat posted above. It's actually a bug and shouldn't be relied on.


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
  •