Jump to content

Recommended Posts

Posted

http://killerphp.com/tutorials/object-oriented-php/php-objects-page-1.php

 

Step 5:

 

<?php

class person {

var $name;

function set_name($new_name) {

$this->name = $new_name;

}

function get_name() {

return $this->name;

}

}

?>

 

### Question ###

 

What is the use of $new_name on that set_name function?

What does it mean when the $new_name is inside the open and close parenthesis?

 

 

I'm just a beginner, thank you for explaining the thought. :D

Posted

$new_name is a parameter inside the method (another name for a "function" within an object: see step 4 on http://killerphp.com/tutorials/object-oriented-php/php-objects-page-1.php). A parameter is a variable that is used within a function/method, so that a programmer can send the function some information for the function/method to use.

 

For example:

 

<?php
function add($x,$y)
{
$total=$x+$y;
return $total;
}

echo "1 + 16 = " . add(1,16);
?>

$x and $y are parameters. When "add(1, 16)" is called, $x contains 1 and $y contains 16. The function uses those variables to perform calculation, then returns the results at the end of the function.

 

More info on functions/parameters: http://www.w3schools.com/php/php_functions.asp and http://www.tizag.com/phpT/phpfunctions.php

Posted

$new_name is a parameter inside the method (another name for a "function" within an object: see step 4 on http://killerphp.com/tutorials/object-oriented-php/php-objects-page-1.php). A parameter is a variable that is used within a function/method, so that a programmer can send the function some information for the function/method to use.

 

For example:

 

<?php
function add($x,$y)
{
$total=$x+$y;
return $total;
}

echo "1 + 16 = " . add(1,16);
?>

$x and $y are parameters. When "add(1, 16)" is called, $x contains 1 and $y contains 16. The function uses those variables to perform calculation, then returns the results at the end of the function.

 

More info on functions/parameters: http://www.w3schools.com/php/php_functions.asp and http://www.tizag.com/phpT/phpfunctions.php

 

Sir Ben, thank you so much! you explained it very well! till next time! :D

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...