Title: How to get variable from another function?
Last modified: August 21, 2016

---

# How to get variable from another function?

 *  Resolved [Raider000](https://wordpress.org/support/users/raider000/)
 * (@raider000)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/how-to-get-variable-from-another-function/)
 * Hi
 * Is it possible to get the single variables from a class, when it looks e.g like
   this?
 *     ```
       function cl_validate() {
       		if (isset($_GET['cl_name']) && !empty($_GET['cl_name'])) : $cl_name = $_GET['cl_name'];
       		endif;
       		if (isset($_GET['cl_email']) && !empty($_GET['cl_email'])) : $cl_email = $_GET['cl_email'];
       		endif;
       		if (isset($_GET['cl_text']) && !empty($_GET['cl_text'])) : $cl_text = $_GET['cl_text'];
       		endif;
       }
   
       function cl_send() {
       		$name = $this->cl_validate()->$cl_name
       }
       ```
   
 * $name should be $cl_name. Both are in the same class.

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [Vignesh Pichamani](https://wordpress.org/support/users/viky081/)
 * (@viky081)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/how-to-get-variable-from-another-function/#post-3977267)
 * Make that variable as global here is the tutorial to do this [http://codex.wordpress.org/Global_Variables](http://codex.wordpress.org/Global_Variables)
 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/how-to-get-variable-from-another-function/#post-3977268)
 * Try using public properties.
    [http://php.net/manual/en/language.oop5.properties.php](http://php.net/manual/en/language.oop5.properties.php)
   Example
 *     ```
       class MyClass {
   
       	public $name;
       	public $email;
       	public $text;
   
       	function cl_validate() {
       		if ( isset( $_GET['cl_name'] ) && !empty( $_GET['cl_name'] ) ) : $this->name = $_GET['cl_name'];
       		endif;
       		if ( isset( $_GET['cl_email'] ) && !empty( $_GET['cl_email'] ) ) : $this->email = $_GET['cl_email'];
       		endif;
       		if ( isset( $_GET['cl_text'] ) && !empty( $_GET['cl_text'] ) ) : $this->text = $_GET['cl_text'];
       		endif;
       	}
   
       	function cl_send() {
   
       		// sets properties
       		$this->cl_validate();
   
       		// use properties in this function
       		$name = $this->name;
       	}
   
       }
       ```
   
 *  Thread Starter [Raider000](https://wordpress.org/support/users/raider000/)
 * (@raider000)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/how-to-get-variable-from-another-function/#post-3977319)
 * Thanks, this helped!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘How to get variable from another function?’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 3 participants
 * Last reply from: [Raider000](https://wordpress.org/support/users/raider000/)
 * Last activity: [12 years, 9 months ago](https://wordpress.org/support/topic/how-to-get-variable-from-another-function/#post-3977319)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
