understanding functions and classes


Posted on 16th Feb 2014 07:03 pm by admin

Code: [Select]
class person {
var $name = "Jimmy Goe";

function get_name(){

echo $this->name;
}
}

I am playing with this very small script that I made using a tutorial. I can get the script to echo out the name using the code above. What I don't get is why I can't do this

Code: [Select]class person {
var $name;

function get_name(){
$name = "Jimmy Goe"
echo $this->name;
}
}

then of course in my index page, I am calling it like this
Code: [Select$joe = new person();

$joe->get_name();

If you decide to answer this question, please be as detailed as possible, I am a newb as you can see and the more information you give or the simpler the explanation, the better.

Thanks for helping

No comments posted yet

Your Answer:

Login to answer
113 Like 33 Dislike
Previous forums Next forums
Other forums

Certain files upload, while others do not
I want to read the data from an uploaded file. Not sure why, but it only uploads for certain files.

Echoing a Variable from a Object
How do I get a variable from the new User Class to echo out in this clasS?

class MyApp
{

AJAX form submit
I recently built a form that submits data to my database with an ajax function that is called throug

Need a fuction to count entries in a field
Hi
I need a fuction to count how many times a email address is entered in to a field.

I ma

LOOPing Problem
Hello All!

The following code loops through the data and displays the data accordingly. My p

Forum tutorial
Im a beginner in PHP. Im making a forum(previous questbook, counter and few others) to learn. For no

firefox wouldnt stream mp3 files completely from my php page
hi everyone,
I have a php file trying to read and stream mp3 files. It works fine in IE but my pr

Suggestions for Functional module
Hello experts,
I Have done B.Sc(Mathematics) and MCA & have learnt SAP/ABAP but do n

Contact Form Not Working When I Add Validation Codes
So I built my first working PHP "Contact Us" like form. But, I have been trying to now mak

TCP Sending Unsigned Char...
Hi...

I want to send over tcp/ip some data, i have the data in hexadecimal, and when i tr

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash