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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problem in PHP 5

    Hey guys..
    I wanted to know how to call a function which is present in a class in 1 file from a class in another file. Please help ASAP. I am using PHP 5...
    Thank you guys

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Statically I presume?
    Code:
    MyOtherClass::method();
    Depending on you're version of PHP depends on how you get it in there though. The end result is always an include/require call against you're other class file, but in 5.3.x+ you can chain it against the spl_autoload method to import using the use keyword.

    PHP Code:
    require_once '/path/to/MyOtherClass.class.php';
    // Or, using spl_autoload if registered directly, include the autoload file and call:
    use /path/to/MyOtherClass AS MyOtherClass// Where MyOtherClass is in namespace /path/to

    class MyClass
    {
        public function 
    __construct()
        {
            
    MyOtherClass::method();
        }

    Now if you mean that this is an Object method, then you'll need to either pass an instance of an object, create a singleton object for instantiation, or globalize you're object (not recommended).
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

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