473,395 Members | 2,468 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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

Jul 17 '05 #1
3 1629
gm****@charter.net wrote:
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...


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.
Jul 17 '05 #2
On 11 Feb 2005 09:15:55 -0800, gm****@charter.net wrote:

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.
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.
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...


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';
Jul 17 '05 #3
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:
On 11 Feb 2005 09:15:55 -0800, gm****@charter.net wrote:

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 = newClassName, so This is what I figure.
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.
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...


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';


Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Randell D. | last post by:
I have just recompiled, upgraded to PHP 4.3.4. As an exercise (and curiosity) I've decided to test out PDF functions and got the test in the PHP online manual working. I had one problem whereby...
2
by: thecrow | last post by:
Alright, what the hell is going on here? In the following code, I expect the printed result to be: DEBUG: frank's last name is burns. Instead, what I get is: DEBUG: frank's last name is...
220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
9
by: Martin Maney | last post by:
In my copious spare time I've been dabbling at getting a computerized version of a board game working. After deciding that tk just made me want to vomit, and wx was like swimming through...
92
by: Reed L. O'Brien | last post by:
I see rotor was removed for 2.4 and the docs say use an AES module provided separately... Is there a standard module that works alike or an AES module that works alike but with better encryption?...
3
by: Ron_Adam | last post by:
Ok... it's works! :) So what do you think? Look at the last stacked example, it process the preprocess's first in forward order, then does the postprocess's in reverse order. Which might be...
12
by: Dario | last post by:
The following simple program behaves differently in Windows and Linux . #include <stdexcept> #include <iostream> #include <string> using namespace std; class LogicError : public logic_error {...
30
by: James Conrad StJohn Foreman | last post by:
After 3 years of using DB2 on Linux, I'm leaving my current employers to go work for a SQL Server shop instead. In order to find my replacement, they're trying to put together a set of questions...
2
by: yogesh | last post by:
char TCGI::x2c(char *what) { register char digit; digit = (char) ((what >= 'A' ? ((what & 0xdf) - 'A')+10 : (what - '0'))); digit *= (char) 16; digit += (char) ((what >= 'A' ? ((what & 0xdf) -...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.