Guest askjames01 Posted May 14, 2006 Share Posted May 14, 2006 <?php//calling variable from inside class within two functions.class a { var $name2; function myfunc($name) { $name2 = $name; $name2 .= ' lastname'; } function call_myfunc() { echo $this->$name2; }}//declare new object$CO_a = new a;$CO_a->call_myfunc('firstname');?>Please take note that i'm using PHP ver. 4.3.1.The action that i want to do here is to re-use $name2 inside call_myfunc().but unfortunately it showing-up me an error message.So what must i do to re-use $name2 inside call_myfunc() Do i need reference here?or serialize?or any bright and easy solution for this?thanks n advance. Quote Link to comment Share on other sites More sharing options...
toplay Posted May 14, 2006 Share Posted May 14, 2006 [code]<?php//calling variable from inside class within two functions.class a {var $name2;function myfunc($name) {$this->name2 = $name; // added $this->$this->name2 .= ' lastname'; // added $this->}function call_myfunc() {echo $this->name2; // Removed $}}//declare new object$CO_a = new a;$CO_a->myfunc('firstname'); // Added to set name2$CO_a->call_myfunc(); // Took out 'firstname' no value passed for this func.?>[/code] Quote Link to comment Share on other sites More sharing options...
Guest askjames01 Posted May 14, 2006 Share Posted May 14, 2006 Thank you very much [b]TOPLAY[/b] [img src=\"style_emoticons/[#EMO_DIR#]/laugh.gif\" style=\"vertical-align:middle\" emoid=\":laugh:\" border=\"0\" alt=\"laugh.gif\" /] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.