Re: One class, many methods: PHP4.x: Q's

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Micky Hulse wrote:
Seems like I have always read/heard that it is best to explicitly pass variables as function parameters... vs throwing around "globals."

Ah, well Chapter 6, page 144-145 have helped clear-up a little bit of my confusion:

"
...<snip>...

Here's a simple class definition of the Person class that shows the $this variable in action:

class Person {
	var $name;
	function get_name() {
		return $this->name;
	}
	function set_name($new_name) {
		$this->name = $new_name;
	}
}
As you can see, the get_name() and set_name() methods use $this to access and set the $name property of the current object.

...<snip>...

Declaring Properties
In the previous definition of the Person class, we explicityly declared the $name property. Property declaration are optional and are simply a courtesy to whoever maintains your program. It's good PHP style to declare your properties, but you can add new properties at any time.

...<snip>...

You can assign default values to properties, but those default values must be simple constants:
var $name = 'J Doe'; // Works
var $age = 0; // Works
var $day = 60*60*60; // Doesn't work.

...<snip>...
"

So, I think I was getting a bit confused with the var variables... But now it looks like it is not bad practice to get and set object "properties", and it almost sounds like it is good practice (though, not required) to declare these properties (var variables) for other eyeballs/programmers.

Man, I love programming in PHP. I just wish I were better at it! :D

K, gonna go practice some on these new techniques.

Cheers,
Micky

--
Wishlists: <http://snipurl.com/1gqpj>
   Switch: <http://browsehappy.com/>
     BCC?: <http://snipurl.com/w6f8>
       My: <http://del.icio.us/mhulse>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux