Re: PHP 4.3.11, question about classes

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

 



On 3/22/06, Michael Hulse <micky@xxxxxxxxxxxxx> wrote:
> Hi,
>
> I am just learning about classes.
>
> My server is running PHP 4.3.11
>
> Example code:
>
> class testing {
>         var $what;
> }
>
> $linkGenClass = new testing();
> $linkGenClass->what = 'hi';
> echo $linkGenClass->what;
>
> Why does the constructor require the "()"?

You're calling a method (which is a function inside a class). You
can't call a regular function without the brackets, so methods should
be the same.

> I have seen many examples via google that do not use "()".

It's better to use them mainly because it's the standard way (c#,
java, c++ all make you use them so better to get into the habit now).

> Should I worry about capitalizing the first letter of the class?

Personal preference. You don't need to.

> Can class names have underscores?

Yes.

> Are spaces allowed on either side of the "->"?

Try it and see what happens :)

> Is "var $what" PHP 4 and 5, whereas "public $what" is PHP 5?

Yes.

Public means you can do:

$linkGenClass->what = 'hi';

private means you can't access it that way.

> Got any good links to class tutorials for PHP 4.3.11?

Shameless plug for my own site :P
http://www.designmagick.com/article/18/PHP/Introduction-to-Object-Oriented-Programming

Other sites:
http://www.phpbuilder.com/columns/luis20000420.php3
http://www.onlamp.com/pub/a/php/2002/07/18/php_foundations.html

> Sorry to sound like a PHP noob.

We all started somewhere :)

--
Postgresql & php tutorials
http://www.designmagick.com/

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