Connecting Tech Pros Worldwide Help | Site Map

what's this? '->'

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 11:27 AM
gmac63@charter.net
Guest
 
Posts: n/a
Default what's this? '->'

All,

I know that '->' is used in object oriented PHP, but I saw this in the
Moodle code (www.moodle.org)

$CFG->dbtype = 'mysql'; // mysql or postgres7 (for now)
$CFG->dbhost = 'localhost'; // eg localhost or db.isp.com
$CFG->dbname = 'moodle'; // database name, eg moodle
$CFG->dbuser = 'root'; // your database username
$CFG->dbpass = 'mypassword'; // your database password
$CFG->prefix = 'mdl_'; // Prefix to use for all table names

You can "echo $CFG->dbtype;" and get "mysql"

This isn't calling functions from an object, rather seems to be
applying properties to a new "object"??? There is no $something = new
ClassName, so This is what I figure.

Its been a while since I cooded PHP and have never seen this. This
seems like a realy good way to apply a number of atttribs to a
"variable" without having to create an array -- unless that is a
shorthand way of creating an array...

Thanks

-Wes Yates


  #2  
Old July 17th, 2005, 11:27 AM
Mark
Guest
 
Posts: n/a
Default Re: what's this? '->'

gmac63@charter.net wrote:
[color=blue]
> All,
>
> I know that '->' is used in object oriented PHP, but I saw this in the
> Moodle code (www.moodle.org)
>
> $CFG->dbtype = 'mysql'; // mysql or postgres7 (for now)
> $CFG->dbhost = 'localhost'; // eg localhost or db.isp.com
> $CFG->dbname = 'moodle'; // database name, eg moodle
> $CFG->dbuser = 'root'; // your database username
> $CFG->dbpass = 'mypassword'; // your database password
> $CFG->prefix = 'mdl_'; // Prefix to use for all table names
>
> You can "echo $CFG->dbtype;" and get "mysql"
>
> This isn't calling functions from an object, rather seems to be
> applying properties to a new "object"??? There is no $something = new
> ClassName, so This is what I figure.
>
> Its been a while since I cooded PHP and have never seen this. This
> seems like a realy good way to apply a number of atttribs to a
> "variable" without having to create an array -- unless that is a
> shorthand way of creating an array...
>[/color]

you need to read this:

http://www.php.net/manual/en/language.oop5.basic.php


they're member variables, which you can also define and get/set on an
object.


mark.



--
I am not an ANGRY man. Remove the rage from my email to reply.
  #3  
Old July 17th, 2005, 11:27 AM
Wayne
Guest
 
Posts: n/a
Default Re: what's this? '->'

On 11 Feb 2005 09:15:55 -0800, gmac63@charter.net wrote:

[color=blue]
>You can "echo $CFG->dbtype;" and get "mysql"
>
>This isn't calling functions from an object, rather seems to be
>applying properties to a new "object"??? There is no $something = new
>ClassName, so This is what I figure.[/color]

If you use a variable as an object PHP automatically creates an object
(I believe this behavior is depreciated in PHP5). There's an implicit
"$something = new stdClass;" if you use a variable as an object.
[color=blue]
>This
>seems like a realy good way to apply a number of atttribs to a
>"variable" without having to create an array -- unless that is a
>shorthand way of creating an array...[/color]

Yeah, I use this all the time. It works with any class...

class SomeClass()
{
}

$test = new SomeClass();
$test->newVar = 'hello';

echo $test->newVar; // prints 'hello';


  #4  
Old July 17th, 2005, 11:28 AM
gmac63@charter.net
Guest
 
Posts: n/a
Default Re: what's this? '->'

WOW! Now that _is_ cool. I figures as much that it creates an object.
The "->" is what PHP uses in oop. Saaaa-wweeeeeet!

Thanks all!

-Wes

Wayne wrote:[color=blue]
> On 11 Feb 2005 09:15:55 -0800, gmac63@charter.net wrote:
>
>[color=green]
> >You can "echo $CFG->dbtype;" and get "mysql"
> >
> >This isn't calling functions from an object, rather seems to be
> >applying properties to a new "object"??? There is no $something =[/color][/color]
new[color=blue][color=green]
> >ClassName, so This is what I figure.[/color]
>
> If you use a variable as an object PHP automatically creates an[/color]
object[color=blue]
> (I believe this behavior is depreciated in PHP5). There's an[/color]
implicit[color=blue]
> "$something = new stdClass;" if you use a variable as an object.
>[color=green]
> >This
> >seems like a realy good way to apply a number of atttribs to a
> >"variable" without having to create an array -- unless that is a
> >shorthand way of creating an array...[/color]
>
> Yeah, I use this all the time. It works with any class...
>
> class SomeClass()
> {
> }
>
> $test = new SomeClass();
> $test->newVar = 'hello';
>
> echo $test->newVar; // prints 'hello';[/color]

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.