Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default new to php classes

    Hi everyone,

    I am new to using classes in PHP development. Can someone tell me if
    it's possible to use a class inside a class. I am developing a class
    that will handle all aspects of MLS listings (real estate). Yet, I want
    to use a PEAR class to extract images from .tar archives. Can I simply
    include this PEAR class into my own class? Or is this bad practice,
    perhaps?

    Thanks in advance,

    Ed
    Ed Koren Guest

  2. Similar Questions and Discussions

    1. two classes
      how can I call class b method b, from class a method a ?
    2. Classes
      do you get an error-message? which? maybe you use var $id = array(); instead of var $id; ciao SVEN Patrik Fomin wrote:
    3. AS2.0 & inner classes
      Greetings... Does ActionScript 2.0 allow the creation of inner classes? Thanks. Respectfully, ASP
    4. First Go at Classes
      So, here I am, I've been programming PHP for 6 years, and have never gotten into classes. Well, I finally decided to take the plunge, and here's my...
    5. ASP Classes vs COM
      For the majority of my work, I just use plain ASP. On the rare occasion that I am doing something intensive that does require user interaction I...
  3. #2

    Default Re: new to php classes

    Ed Koren wrote:
    > I am new to using classes in PHP development. Can someone tell me if
    > it's possible to use a class inside a class. I am developing a class
    > that will handle all aspects of MLS listings (real estate). Yet, I
    > want to use a PEAR class to extract images from .tar archives. Can I
    > simply include this PEAR class into my own class? Or is this bad
    > practice, perhaps?
    >
    Shure you can this, as long as you call the class static or use an object
    instance to reference it:

    class SomeClass {
    function sayHello () {
    print "hello";
    }
    }

    // Static call to SomeClass
    class StaticCaller {
    function callSayHello () {
    SomeClass::sayHello();
    }
    }

    // Create object instance and use that
    class InstanceCaller {
    function callSayHello () {
    $someclass = new SomeClass;
    $someclass->sayHello();
    }
    }


    HTH;
    JW



    Janwillem Borleffs Guest

  4. #3

    Default Re: new to php classes

    Ed Koren wrote:
    > I am new to using classes in PHP development.**Can*someone*tell*me*if
    > it's possible to use a class inside a class.**I*am*developing*a*class
    > that will handle all aspects of MLS listings (real estate).**Yet,*I*want
    > to use a PEAR class to extract images from .tar archives.**Can*I*simply
    > include this PEAR class into my own class?**Or*is*this*bad*practice,
    > perhaps?
    You could be wanting to do one of two things.

    The first is to inherit/derive a new class from an existing one eg:

    class foo {
    var $somevar;
    function doSomething() {
    }
    }

    class bar extends foo {
    function doSomethingElse();
    }

    $bar = new bar();
    $bar->doSomething(); // inherited method call
    $bar->somevar = 1; // setting value of inherited property
    $bar->soSomethingElse(); // calling method from new class


    The second possibility (which I think is probably more along the lines of
    what you are wanting to do) is to just have a class property which is
    another class object eg:

    class foo {
    function doSomething() {
    }
    ...
    }

    class bar {
    var $foo;
    function bar() {
    $this->foo = new foo();
    }
    ...
    }

    $bar = new bar();
    $bar->foo->doSomething();

    --
    Chris Hope - The Electric Toolbox - [url]http://www.electrictoolbox.com/[/url]
    Chris Hope Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139