Jump to content

Creating Classes - Setting A Variable To A Value


geno11x11

Recommended Posts

I'm trying to understand OOP and class construction. I have found many examples of building classes, but I am not clear on the purpose of one step:

 

Here's some code:

 

<?php

class person

{

var $name;

function set_name($new_name)

{

$this->name = $new_name;

}

 

function get_name() {

return $this->name;

}

}

?>

 

My question involves the statement: $this->name = $new_name.

 

I understand the usage of $this and that the variable name is being set to the value of $new_name. Since $new_name has no value, it appears the statement may be used to create an element of the class. So, in the process of building a class, what does this statement do, and why is it required?

Edited by Geno
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...