Jump to content
Stef's Coding Community
Sign in to follow this  
Guest yquetales

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

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

Share this post


Link to post
Share on other sites

$email = $rodrigo->get_email();

 

$email now contains his email address

 

just echo it out.

 

<a href=website.com/index.php?content=contact&email=<?php echo $email; ?>>Contact</a>

Share this post


Link to post
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...
Sign in to follow this  

×
×
  • Create New...