Grow your CSS skills. Land your dream job.

What do you call php variables like this: $this->hello

  • # September 9, 2009 at 2:16 pm

    They must have a name but I can’t find it.

    What’s the arrow called?

    # September 9, 2009 at 5:00 pm

    not sure you have it right but….

    your variable is a variable, but it is looking for a logical answer, therefore it should be looking for a boolean value

    # September 9, 2009 at 5:07 pm

    hmm, That sort of makes sense. Sometimes I see them with a function like:

    Code:
    $this->function();
    # September 9, 2009 at 5:59 pm

    I found this online…..

    Code:
    function FillList ($sql, $selected=0)
    {

    $row = array();
    $cnt = 0;
    $this->query_fill=new Query ($sql, $this->conn);
    $result=$this->query_fill->subExecute();
    while ($row = mysql_fetch_row($result)) {

    $id = $row[0];
    $name = $row[1];

    $cnt += 1;
    if ($selected == $id) {
    echo ““;
    } else {
    echo ““;
    }
    }

    $this->query_fill->Free();
    return $cnt;

    lets take this example……
    $this->query_fill=new Query ($sql, $this->conn);

    Now I don’t know the code or what it is really doing, but I will hazard a guess.
    $this – this would be the this object, a bit like referencing itself
    -> is porobably an SQL type command to attach the query_fill
    = new Query()- this is just making a new object of Query
    $sql, $this->conn – take the $sql variable and pass it in the new object
    $this – referencing itself
    ->conn – maybe an sql command to make a connection.

    so if your really more interested in the -> part of your question I would look up sql php interaction

    http://www.w3schools.com/PHP/func_mysql … object.asp
    http://us.php.net/manual/en/function.my … object.php

    # September 17, 2009 at 11:38 am

    Well, pHp is quite similar to c / c++ and in c++, the term obj->item is used to access the item of the class of which obj is an object.
    Don’t know if it means the same here in pHP or not.Anyway, I have to brush up my C++ a bit.. been ages since I last used it. Am more of a C guy hehe. Will study a bit and get back to you :)

    # September 17, 2009 at 5:07 pm

    You use this when you access a variable which is set in a class. These variables are called properties of a class.

    $this-> stands for a property in the current class you are working in. and hello for the name.

    Code:
    < ?php

    class Example {

    public $hello = 'hello doug';
    public $msg = 'how are you doing?';

    function test(){
    echo 'test';
    }
    }
    ?>

    So in the example above $this->hello stands for ‘hello doug’.

    Its used in objective oriented programming in php (or short: OOP).
    So maybe you can find more info with those words.

    Rob
    # September 17, 2009 at 6:14 pm

    yup the guys above are right – you could set up a new object by assigning for example a class you made to connect to a database…

    $this = new connection();

    connection is the class you are accessing – inside the class are the functions – (well methods if they are inside a class – but hey…)

    you can then access the functions/methods via the "->"

    $this->addNew();

    if you see "=>" that is what defines a key within an array – it can be a little double take-ish when you first see it though…

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".