Jump to content

How to get the value of a variable from a class method?


Guest yquetales

Recommended Posts

Guest yquetales

Say I have a class person with a method that returns some value, for instance an email address.

<?php

something like class person{

var $email;

function set_email($new_email){

$this->email = $new_email;

}

 

function get_email(){

return $this->email;

 

}

}

?>

 

if I call this method from a view file

say

<?php

$rodrigo = new person();

$rodrigo->set_email("rodrigo@hotmail.com");

 

I can display the email using echo "his email is :".$rodrigo->get_email();

 

but what if I want to retrieve his email from a database for instance to use it in a link:

for example if I want to do this <a href=website.com/index.php?content=contact&email=$email>Contact</a> where $email should be rodrigo's email. What should I do to get rodrigo's email from the method get_email(); into a variable??

?>

 

Maybe this is a very simple question, but I appreciate your help. Thanks

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