Page 2 of 4 FirstFirst 1234 LastLast
Results 11 to 20 of 32
Like Tree6Likes

Thread: Php oop!

  1. #11
    Senior Member softwarefreak's Avatar
    Join Date
    Jun 2011
    Location
    http://softwarefreak.in
    Posts
    347
    Thanks
    142
    Thanked 211 Times in 69 Posts
    Rep Power
    2

    Default

    Quote Originally Posted by StunningNick [Only registered and activated users can see links. Click Here To Register...]
    i think "$this" represent non-static call , don't get me wrong, I'm an noob willing to learn :P
    Ok master, got it :D

    added after couple of minutes :D (just phped php.net for perfect answer)

    $this is a reference to the calling object (usually the object to which the method belongs, but possibly another object
    Last edited by softwarefreak; 18-03-12 at 19:19.
    I need some facebook likes, can you please help me
    [Only registered and activated users can see links. Click Here To Register...]
    I noticed social media is really powerful
    Well DONE is better than well SAID

  2. #12
    Member StunningNick's Avatar
    Join Date
    Nov 2011
    Posts
    40
    Thanks
    6
    Thanked 49 Times in 7 Posts
    Rep Power
    0

    Default this

    Quote Originally Posted by softwarefreak [Only registered and activated users can see links. Click Here To Register...]
    $this represents the object inside the class
    i think "$this" represent non-static call , don't get me wrong, I'm an noob willing to learn :P
    none of us is wrong technically/programatically...

    "this" represent an non-static call to an object/method/variable bla bla bla etc... thanks for correction Dude :cheers:
    softwarefreak likes this.

  3. #13
    Senior Member something else's Avatar
    Join Date
    Feb 2008
    Location
    if($something){echo 'Status code 404'; }else{ echo 'coding-talk.com';}
    Posts
    1,818
    Thanks
    209
    Thanked 447 Times in 202 Posts
    Rep Power
    0

    Question

    im a noob at oop ..... how do you call for a function within a function within the same class ?
    softwarefreak likes this.

    [Only registered and activated users can see links. Click Here To Register...]


  4. #14
    Administrator GumSlone's Avatar
    Join Date
    Mar 2005
    Location
    Mars, GumCity
    Posts
    1,495
    Thanks
    125
    Thanked 573 Times in 201 Posts
    Blog Entries
    2
    Rep Power
    10

    Default

    Quote Originally Posted by something else [Only registered and activated users can see links. Click Here To Register...]
    im a noob at oop ..... how do you call for a function within a function within the same class ?
    Not oop: function_name();

    Oop: $this->function_name();
    DiL likes this.
    Advertise your mobile site for FREE with [Only registered and activated users can see links. Click Here To Register...]

    [Only registered and activated users can see links. Click Here To Register...]


  5. #15
    Senior Member something else's Avatar
    Join Date
    Feb 2008
    Location
    if($something){echo 'Status code 404'; }else{ echo 'coding-talk.com';}
    Posts
    1,818
    Thanks
    209
    Thanked 447 Times in 202 Posts
    Rep Power
    0

    Question

    I mean if i have got a class like:
    PHP Code:
    <? 
    class someclass{

    funtion function1(){
     
    //do something here
    }

    funtion function2(){
      
    //how do i use function1 here?
    // $someclass->function1();  //tried this and it caused errors
    // or is it $this->function1(); //i havent tried using this
    }

    }
    ?>

    [Only registered and activated users can see links. Click Here To Register...]


  6. #16
    Member antony2kx's Avatar
    Join Date
    Jun 2010
    Location
    prospect, manchester, jamaica
    Posts
    94
    Thanks
    4
    Thanked 12 Times in 12 Posts
    Rep Power
    3

    Default

    example OOP wapcreate.com is pure OOP and is built upon MVC architecture

    PHP Code:

    class Car {

    private 
    $carname;
    private 
    $caryear;
    public 
    object;

    public function 
    __construct($carname$caryear)
    {
       
    self::setName($carname); //this could also be done using $this->setName($carname) or Car::setName($carname)
       
    self::setYear($caryear);
    }

    public function 
    setYear($y)
    {
       
    $this->caryear $y;
    }

    public function 
    setName($n)
    {
       
    $this->carname $n;
    }


    public function 
    getName()
    {
       return 
    $this->carname;
    }

    public function 
    getYear()
    {
      return 
    $this->caryear;
    }

    }; 
    // the semicolon is not needed here

    usage of this class will be 

    $car 
    = new Car("Lamboginy""2010");

    you can now use the get methods to access properties of this class

    like if you wanted to print the year of the car it will be like

    echo $car->getYear(); will print 2010;

    you can also have objects within other objects like 

    $car
    ->object = new Car("BMW""2011");

    echo 
    $car->object->getName(); will print BMW 

  7. The Following User Says Thank You to antony2kx For This Useful Post:

    something else (19-03-12)

  8. #17
    Administrator GumSlone's Avatar
    Join Date
    Mar 2005
    Location
    Mars, GumCity
    Posts
    1,495
    Thanks
    125
    Thanked 573 Times in 201 Posts
    Blog Entries
    2
    Rep Power
    10

    Default

    PHP Code:
    <? 
    class someclass{

    function 
    function1(){
     
    //do something here
    }

    function 
    function2(){

    $this->function1();
    }

    }
    ?>
    or outside
    PHP Code:
    $c = new someclass;
    $c->function1();
    $c->function2(); 
    call function3 in a class which is not inside the class:
    PHP Code:
    <? 
    function function3()
    {
    return 
    'do something';
    }

    class 
    someclass{

    function 
    function1(){
     
    //do something here
    }

    function 
    function2(){
    $something_inside $this->function1();
    $something_outside function3();
    }

    }
    ?>
    Advertise your mobile site for FREE with [Only registered and activated users can see links. Click Here To Register...]

    [Only registered and activated users can see links. Click Here To Register...]


  9. The Following User Says Thank You to GumSlone For This Useful Post:

    something else (19-03-12)

  10. #18
    Senior Member something else's Avatar
    Join Date
    Feb 2008
    Location
    if($something){echo 'Status code 404'; }else{ echo 'coding-talk.com';}
    Posts
    1,818
    Thanks
    209
    Thanked 447 Times in 202 Posts
    Rep Power
    0

    Default

    im guessing if you have got 2 classes then to use a function from the second class in the first class function you would use the same method as calling it outside the class?
    eg:
    PHP Code:
    <?
    class someclass{

    function 
    function1(){
    $c = new someclass2
    $c->function2();
    }

    }

    class 
    someclass2{

    funtion function2(){

    }

    }
    ?>

    [Only registered and activated users can see links. Click Here To Register...]


  11. #19
    Member antony2kx's Avatar
    Join Date
    Jun 2010
    Location
    prospect, manchester, jamaica
    Posts
    94
    Thanks
    4
    Thanked 12 Times in 12 Posts
    Rep Power
    3

    Default

    That is one way at something else

    or you can do it by extending the first class by the second one

    for example


    PHP Code:


    class Class1{

    public function 
    functionInClassOne()
    {
    echo 
    "hello worlds";
    }



    }


    class 
    Class2 extends Class1{

    public function 
    printHelloWorld()
    {
       
    $this->functionInClassOne(); //this will use the methods in class 1 because u have extended it
    }

    }

    so instance would be 

    $instance 
    = new Class2;

    $instance->printHelloWorld(); 

    as easy as it gets

  12. The Following User Says Thank You to antony2kx For This Useful Post:

    something else (19-03-12)

  13. #20
    Senior Member something else's Avatar
    Join Date
    Feb 2008
    Location
    if($something){echo 'Status code 404'; }else{ echo 'coding-talk.com';}
    Posts
    1,818
    Thanks
    209
    Thanked 447 Times in 202 Posts
    Rep Power
    0

    Default

    what im a little confused about when using oop it makes your script a lot longer
    does this make it longer to process?

    [Only registered and activated users can see links. Click Here To Register...]


Page 2 of 4 FirstFirst 1234 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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
  •  

SEO by vBSEO

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19