Jump to content

CLASS question *SOLVED*


Guest askjames01

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.
Link to comment
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]
Link to comment
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\" /]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.