Jump to content

Recommended Posts

PHP 5 stuff, it wont work correctly with PHP 4.

 

How would I do this just using PHP 4?

 

I got an error with your example:

 

Parse error: syntax error, unexpected T_VAR, expecting T_VARIABLE in C:\SERVER\www\foobar.php on line 4

 

 

I'm using WAMP 5 PHP 5.2.3

I suppose that it isn't necessary to declare a function public, since according to the manual a method without a declaration is automatically public (http://us2.php.net/manual/en/language.oop5.visibility.php#language.oop5.visiblity-methods).

 

I do it mostly for consistency, and also because I suppose that I'm slightly OCD.

 

Remove the public / protected from the vars and methods, and change the function named "__construnct" to the name "foo".

I suppose that it isn't necessary to declare a function public, since according to the manual a method without a declaration is automatically public (http://us2.php.net/manual/en/language.oop5.visibility.php#language.oop5.visiblity-methods).

 

I do it mostly for consistency, and also because I suppose that I'm slightly OCD.

 

Remove the public / protected from the vars and methods, and change the function named "__construnct" to the name "foo".

 

Ok cool it worked perfectly:

 

<?php

class foo {
var $bar;

function foo () {
	$this->bar = new bar();
}
}

class bar {
function foo_bar() {
	return "FUBAR (F'd Up Beyond All Repair)";
}
}

$blah = new foo;

echo $blah->bar->foo_bar();

?>

IMHO, specifying things which are the default anyway (such as public) is good practice.  It adds to the documentation, and ensures your code will run correctly even if the defaults change.  It also helps catch bugs, as you may not always be correct in what you assume the default to be.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.