View Single Post
Old 07-12-2005, 12:03 PM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,489
sde is on a distinguished road
first of all, no need for the 'pathetic question' setup =) .. it's a great question.

-> in php is how you access functions or variables of an object. in your example, this would be the object.

you only use the keyword this when you are accessing properties of a class that you are currently coding in.

i wrote this article a while back. it's just a little introduction to object oriented (OO) programming with php.

Lots of things have changed with OO programming and PHP with PHP5. keep in mind that the link above was written for php4, so it may not be proper PHP5 as far as the style of a class goes.

to answer your question exactly, you are just concatinating aclass varaible with "some_text". the dot in PHP just glues strings together.

it would be the same thing as this:
PHP Code:
<?
$inv_table 
"<table border=1><tr><td>";
$end_table "</td></tr></table>";

echo 
$inv_table."some text".$end_table;
?>
Other languages such as Java and Javascript are a little different to PHP in this case. They use a + to concatinate ( where php uses a dot ) .. also they use a dot to access a class property ( where php uses -> )

if it was a class, it might look something like this:
PHP Code:
<?
class MyClass(){
  
$this->inv_table "<table border=1><tr><td>";
  
$this->end_table "</td></tr></table>";

  function 
printTextInTable($some_text){
    echo 
$this->inv_table $some_text $end_table;
  }

  
// this is an example of calling a function
  // within the class with this->
  
function printWelcome(){
    
$this->printTextinTable("Welcome");
  }
}

// now i can use my class to make tables with text
$mc = new MyClass();

// now call the function inside the class.. except this time
// we will be using $mc instead of $this since we are outside the class
$mc->printTextInTable("this will print inside an html table");
?>
probably not the best examples, but feel free to ask more questions if you don't understand.
__________________
Mike
sde is offline   Reply With Quote