By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,816 Members | 2,053 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,816 IT Pros & Developers. It's quick & easy.

Call function from converted Array ?

100+
P: 150
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $ar = (object) array('a'=>function(){
  3.     echo 'TEST';
  4. });
  5. $ar->a();
  6. ?>
I get this error Call to undefined method
Apr 9 '12 #1
Share this Question
Share on Google+
8 Replies


Dormilich
Expert Mod 5K+
P: 8,639
var_dump($ar)
that should give you an idea, what your object looks like.
Apr 10 '12 #2

100+
P: 150
can you tell me how can i call the function ?
Apr 10 '12 #3

Dormilich
Expert Mod 5K+
P: 8,639
what’s the output from var_dump($ar) ?
Apr 10 '12 #4

100+
P: 150
object(stdClass)[2]
public 'a' =>
object(Closure)[1]
Apr 10 '12 #5

Dormilich
Expert Mod 5K+
P: 8,639
try {$ar->a}();. the point is that "a" is not a Method, it’s a Property (and unlike to JavaScript, that’s not the same)
Apr 10 '12 #6

100+
P: 150
Parse error: syntax error, unexpected '}' in
Apr 10 '12 #7

Dormilich
Expert Mod 5K+
P: 8,639
then you did not copy correctly
Apr 10 '12 #8

100+
P: 150
I did copy it correctly maybe my version of PHP 5.3.10 ?



Apr 10 '12 #9

Post your reply

Sign in to post your reply or Sign up for a free account.