Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 135,998 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 2,388 people online right now. Registration is fast and FREE... Join Now!




Reasons for using some expressions ?s

 
Reply to this topicStart new topic

Reasons for using some expressions ?s

BetaWar
9 Jan, 2007 - 03:50 PM
Post #1

#include <soul.h>
Group Icon

Joined: 7 Sep, 2006
Posts: 2,011



Thanked: 81 times
Dream Kudos: 1175
My Contributions
Okay I have noticed in some scripts at various sites that they use additional expresions which have so far, kinda confused my for their useage.

I have seen ones that have something like:
@$variable;

And:
$this->

and would like to know what that means when you add it into your script.

I have beena ble to make some since out of $this, but only in a script like so:

CODE

class test{

  function one($var){

    $var = 'nothing...';
    return $var;

  }
  function two($var){

    $var = 'Welcome ' .$var;
    return $var;

  }
  function init($var){

    $this = &NEW test;
    $variable = $this->one($var);
    $variable .= $this->two($var);
    return $variable;

  }
}


Any help on understanding these would be appreciated.
User is offlineProfile CardPM
+Quote Post

snoj
RE: Reasons For Using Some Expressions ?s
9 Jan, 2007 - 05:17 PM
Post #2

$Null
Group Icon

Joined: 31 Mar, 2003
Posts: 3,304



Thanked: 6 times
Dream Kudos: 700
My Contributions
Placing an @ before something hides errors it may raise. It's usful when you know something is going to raise an error or want to hide an error from an end user.

The $this is used in classes to access the classes proporties or methods.
User is offlineProfile CardPM
+Quote Post

BetaWar
RE: Reasons For Using Some Expressions ?s
9 Jan, 2007 - 05:24 PM
Post #3

#include <soul.h>
Group Icon

Joined: 7 Sep, 2006
Posts: 2,011



Thanked: 81 times
Dream Kudos: 1175
My Contributions
Okay that is nice to know, I have a couple more questions now...

why won't it work to (while in a class) simply call:
$this->two($act);
without first setting
$this = &NEW test;

Also what does the & do? Is it like the . in a statement?
I mean something like so:
echo'hello ' . $name;
and
echo'hello ' & $name;
or is it for something else?
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Reasons For Using Some Expressions ?s
9 Jan, 2007 - 05:30 PM
Post #4

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,226



Thanked: 36 times
Dream Kudos: 25
My Contributions
CODE

$this = &NEW test;

The code above declares a variable names this, and instantiates to be of type test. If this instantiation is not made, then there is no variable object named this for which to access methods.

As for your second question, you may wish to have an overview of php operators.

http://ca.php.net/operators

User is offlineProfile CardPM
+Quote Post

snoj
RE: Reasons For Using Some Expressions ?s
9 Jan, 2007 - 05:40 PM
Post #5

$Null
Group Icon

Joined: 31 Mar, 2003
Posts: 3,304



Thanked: 6 times
Dream Kudos: 700
My Contributions
QUOTE
why won't it work to (while in a class) simply call:
$this->two($act);
without first setting
$this = &NEW test;
You don't have to do that because $this is a given. Since you're in the class already, you and the PHP engine always know what $this is.

User is offlineProfile CardPM
+Quote Post

BetaWar
RE: Reasons For Using Some Expressions ?s
9 Jan, 2007 - 05:46 PM
Post #6

#include <soul.h>
Group Icon

Joined: 7 Sep, 2006
Posts: 2,011



Thanked: 81 times
Dream Kudos: 1175
My Contributions
Okay, thanks that is a nice resource smile.gif

And Hotsnoj, do you know what PHP version $this being auto set becomes available at?

This post has been edited by BetaWar: 9 Jan, 2007 - 05:47 PM
User is offlineProfile CardPM
+Quote Post

snoj
RE: Reasons For Using Some Expressions ?s
9 Jan, 2007 - 05:57 PM
Post #7

$Null
Group Icon

Joined: 31 Mar, 2003
Posts: 3,304



Thanked: 6 times
Dream Kudos: 700
My Contributions
As far as I know it's always been that way. The only time $this isn't set by PHP is when the method is called statically (i.e. class::method()).
User is offlineProfile CardPM
+Quote Post

BetaWar
RE: Reasons For Using Some Expressions ?s
9 Jan, 2007 - 06:09 PM
Post #8

#include <soul.h>
Group Icon

Joined: 7 Sep, 2006
Posts: 2,011



Thanked: 81 times
Dream Kudos: 1175
My Contributions
Okay thanks, I figured out how to use it.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 12:03PM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month