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 4 of 4
  1. #1
    Regular Coder
    Join Date
    Sep 2004
    Posts
    713
    Thanks
    6
    Thanked 2 Times in 2 Posts

    use another class within one class

    Hello

    i happen need to use another class inside current class, what shall i do? use normal way like "$k=new image();"?

    Thanks
    flying dagger

  • #2
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    either that, or pass the instance in either via the constructor or via a 'setter' method. Both of these will result in a less tightly coupled system, which is generally a good thing.

    If you provide more information (what are the classes in question?) you'll be more likely to receive a decent answer.
    My thoughts on some things: http://codemeetsmusic.com
    And my scrapbook of cool things: http://gjones.tumblr.com

  • #3
    Regular Coder
    Join Date
    Sep 2004
    Posts
    713
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Hi

    thanks for reply

    Code:
    	$image = new Gimage();
    	$image->limit="100";
     
    	$image->save_file = $thumbpath;
    	$image->create($newname);
    above is the codes i want to use in below class

    Code:
    class zip
    {
    }
    how to write in class "zip"?
    flying dagger

  • #4
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    what is zip? how are you using it? what does it have to do with a Gimage?
    There are a few different ways:
    PHP Code:
    class Zip {
      public function 
    foo() {
        
    $img = new Gimage();
        
    $this->bar $img->baz();
      }
    }
    //or
    class Zip {
      public function 
    foo(GImage $img) {
        
    $this->bar $img->baz()
      }
    }
    //or
    class Zip {

      protected 
    $img;

      public function 
    __construct(GImage $img) {
        
    $this->img $img;
      }

      public function 
    foo() {
        
    $this->bar $this->img->baz();
      }

    }
    //or
    class Zip {
        protected 
    $img;

        public function 
    setGImage(GImage $img) {
          
    $this->img $img;
        }

        public function 
    foo() {
          
    $this->bar $this->img->baz();
        }

    My thoughts on some things: http://codemeetsmusic.com
    And my scrapbook of cool things: http://gjones.tumblr.com

  • Users who have thanked GJay for this post:

    xiaodao (10-28-2007)


  •  

    Posting Permissions

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