1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Stupid Question

Discussion in 'PHP' started by Pudge1, Nov 6, 2013.

  1. #1
    This is most likely a very stupid question and you would think for someone who has been coding with PHP for 4 years now I would know the answer to it but I've never came across something that I was coding where I needed to use this.

    What does $variable->SomethingElse do? I've seen it quite often in code but I really have no clue what it really does, nor do I know how I would Google a question phrased to get an answer to that.
    SEMrush
     
    Pudge1, Nov 6, 2013 IP
    SEMrush
  2. ryan_uk

    ryan_uk Illustrious Member

    Messages:
    3,983
    Likes Received:
    1,022
    Best Answers:
    33
    Trophy Points:
    465
    #2
    Take a look at Object Oriented programming with PHP and that will explain it:
    http://php.net/manual/en/language.oop5.php

    I guess you have been doing "procedural programming". That is what I first learnt (and prefer).
     
    ryan_uk, Nov 6, 2013 IP
  3. rehan.khalid.9235

    rehan.khalid.9235 Active Member

    Messages:
    78
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    85
    #3
    lets have a look at the below example:-

    class UserController extends Controller {
            public $user_id;
    
          public function actionInitialize() {
              $this->user_id=1;
          }
    }
    PHP:
    now if you see the above code, its an example of Object oriented programming in Php. where as ' $this ' refers to the object of the Class 'UserController' . Since, $user_id is an attribute of a class so it can be access via:-

    1) setters and getters
    2) Scope resolution operation (some restriction , as it has to be static)
    3)$this
     
    rehan.khalid.9235, Nov 7, 2013 IP
  4. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #4
    for me that is one of the downside of php, procedural programming, really high level type of programming (more on dynamic websites), but fast implementation though.
    it will be really hard in programming if you start from php, but not vice versa.

    ok based on your example
    $variable->SomethingElse
    Code (markup):
    - this is just calling the variable "SomethingElse" inside the class implementation on your variable "$variable"
    thus
    $variable->SomethingElse()
    Code (markup):
    - this one calls the method/function inside the class implementation on your variable "$variable" (notice the parentheses '()')

    given this class
    class Example {
          $SomethingElse = "HelloWorld";
          public function SomethingElse() {
              return "Hellow"
          }
    }
    Code (markup):
     
    bartolay13, Nov 7, 2013 IP
    ryan_uk likes this.