Jump to content

Archived

This topic is now archived and is closed to further replies.

Guest askjames01

CLASS question *SOLVED*

Recommended Posts

Guest askjames01
<?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.

Share this post


Link to post
Share on other sites
[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]

Share this post


Link to post
Share on other sites
Guest askjames01
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\" /]

Share this post


Link to post
Share on other sites

×

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.