[php] - Problem! Object Oriented. Accessing Variable In Function A In Function B - Webmasters - Nairaland
Nairaland Forum › Science/Technology › Webmasters › [php] - Problem! Object Oriented. Accessing Variable In Function A In Function B (1026 Views)
| [php] - Problem! Object Oriented. Accessing Variable In Function A In Function B by Mobinga(op): 2:47pm On Jul 15, 2011 |
I have two functions.
and
I want to access variable $meh which is declared in the first function, in the second function. However, when I echo/print_r $meh from the second version it returns 0. I know I'm doing something wrong. This has been bugging me for days! Thanks. ![]() |
| Re: [php] - Problem! Object Oriented. Accessing Variable In Function A In Function B by Mobinga(op): 2:49pm On Jul 15, 2011 |
No Globals! |
| Re: [php] - Problem! Object Oriented. Accessing Variable In Function A In Function B by DualCore1: 3:38pm On Jul 15, 2011 |
In my opinion, won't work. Your function must return something. |
| Re: [php] - Problem! Object Oriented. Accessing Variable In Function A In Function B by quadrillio(m): 3:50pm On Jul 15, 2011 |
@OP since you don't want to a create class and do the GLOBAL var stuff, Why not make the function return a variable, something like this should do the magic.
and
now you need the final piece that will show the final output and that is by calling 'themw_user_butt()'
if all code is meant to be in one page here is what u should have
I hope this helps - SAFE. |
Can You Solve This PHP Problem?? • Procedural Vs Object Oriented PHP • Php Problem: Retrieving Images And Display In Horizontally Format. • 2 • 3 • 4
Share Ur Twitter Handles • Pls I Need Joomsocial Or Any Social Network Development Tool! • Download Eleven40 Blogger Template By Lord HTML
