calling a random method in a class constructor

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

Post Reply
joevis
Forum Newbie
Posts: 5
Joined: Tue Mar 22, 2011 6:50 pm

calling a random method in a class constructor

Post by joevis »

Hello, I have about 40 or so functions in a class I created but it won't seem to let me call a random one using a variable in the constructor.

The code looks like this
class superclass {

function __construct() {
$num = rand(1,40);
$name = "fname_" . $num;
superclass::$name
}

function fname_1() {
}

function fname_2() {
}

3,4,5 etc.
}
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: calling a random method in a class constructor

Post by social_experiment »

Have you tried passing the argument to the constructor?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
joevis
Forum Newbie
Posts: 5
Joined: Tue Mar 22, 2011 6:50 pm

Re: calling a random method in a class constructor

Post by joevis »

social_experiment wrote:Have you tried passing the argument to the constructor?
awesome thanks.
Post Reply