Newbie to Classes, I need some Guru help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Try looking at this recursive directory scanner feyd coded once. That might help you wrap your mind around what you are doing. The next step is learning how to instantiate an object. When you place a parameter in the constructor of the class, and you call the class without the parameter, you are going to have trouble.

Also, you may want to make sure you are developing with error_reporting set to E_ALL and display_errors on.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Ahem. I didn't do recursion in those snippets; Scottayy did.

;)
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Sorry. Forgot about that.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

cesarcesar wrote:Mr The Moose, thanks but is still no progress.
Anyway, $class = new DirTree(); won't work. You have to pass a parameter here.

take a look at

Code: Select all

<?php
class FooA {
	function FooA() {
		echo ' FooA ';
	}
}

class FooB {
	function FooB($x) {
		echo " FooB($x) ";
	}
}

class FooC {
	function FooC($x, $y) {
		echo " FooC($x, $y) ";
	}
}


$a = new FooA;  // ok, the FooA's constructor doesn't need a parameter

// $b = new FooB; // warning, FooB's constructor needs one parameter
$b = new FooB(1);

// $c = new FooC; // warning, FooB's constructor needs two parameters
// $c = new FooC(1); // warning, FooB's constructor needs two parameters
$c = new FooC(1,2);
Post Reply