Login or Sign Up
Logging in...
Remember me
Log in
Or
Sign Up
Forgot password or user name?
Log in with
Search in titles only
Search in PHP only
Search
Advanced Search
Forums
Product Launch
Updates
Today's Posts
Member List
Calendar
Home
Forum
Topic
PHP
Call function from converted Array ?
Collapse
X
Collapse
Posts
Latest Activity
Photos
Page
of
1
Filter
Time
All Time
Today
Last Week
Last Month
Show
All
Discussions only
Photos only
Videos only
Links only
Polls only
Events only
Filtered by:
Clear All
new posts
Previous
template
Next
smartic
New Member
Join Date:
May 2007
Posts:
150
#1
Call function from converted Array ?
Apr 9 '12, 03:18 PM
Code:
<?php $ar = (object) array('a'=>function(){ echo 'TEST'; }); $ar->a(); ?>
I get this error
Call to undefined method
Dormilich
Recognized Expert
Expert
Join Date:
Aug 2008
Posts:
8694
#2
Apr 10 '12, 05:47 AM
var_dump($ar)
that should give you an idea, what your object looks like.
Comment
Post
Cancel
smartic
New Member
Join Date:
May 2007
Posts:
150
#3
Apr 10 '12, 08:18 AM
can you tell me how can i call the function ?
Comment
Post
Cancel
Dormilich
Recognized Expert
Expert
Join Date:
Aug 2008
Posts:
8694
#4
Apr 10 '12, 08:20 AM
what’s the output from
var_dump($ar)
?
Comment
Post
Cancel
smartic
New Member
Join Date:
May 2007
Posts:
150
#5
Apr 10 '12, 08:23 AM
object(stdClass )[2]
public 'a' =>
object(Closure)[1]
Comment
Post
Cancel
Dormilich
Recognized Expert
Expert
Join Date:
Aug 2008
Posts:
8694
#6
Apr 10 '12, 08:29 AM
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)
Comment
Post
Cancel
smartic
New Member
Join Date:
May 2007
Posts:
150
#7
Apr 10 '12, 08:51 AM
Parse error: syntax error, unexpected '}' in
Comment
Post
Cancel
Dormilich
Recognized Expert
Expert
Join Date:
Aug 2008
Posts:
8694
#8
Apr 10 '12, 09:32 AM
then you did not copy correctly
Comment
Post
Cancel
smartic
New Member
Join Date:
May 2007
Posts:
150
#9
Apr 10 '12, 10:30 AM
I did copy it correctly maybe my version of PHP 5.3.10 ?
Comment
Post
Cancel
Previous
template
Next
Working...
Yes
No
OK
OK
Cancel
👍
👎
☕
Comment