Jump to content

OOP why does this not work?


johnsmith153

Recommended Posts

Why does this not work (of course if I change the line I have commented then it will)?

 

I am trying to see how I would do something like this.

 


<?php

class ClassName {

var $var = "hello";

public function methodName($class, $method) {
	$class::$method($this->var);
	//Class2::anotherMethod($this->var);	
}

}

class Class2 {

static function anotherMethod($val) {
	echo "You said: ".$val;
}

}

$newClass = new ClassName();
$newClass->methodName("Class2", "anotherMethod");

?>

Link to comment
Share on other sites

what version of php are you using when i run it on 5.3 it works but if i would have to guess i would say your on an older version of php because if you look here

 

http://php.net/manual/en/language.oop5.static.php

 

it says that the first method of calling a static function was added in 5.3

 

Yes, use this:

 

call_user_func(array($class, $method), $this->var);

Link to comment
Share on other sites

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.