MDanz Posted February 26, 2011 Share Posted February 26, 2011 i have two functions. In function two it has $id=9. how do i get function one to echo $id? how do i adjust the below example to accomplish this? $newdb = new Database(); class Database { function one() { $newdb->two(); echo $id; } function two() { $id = 9 return $id; } } Link to comment https://forums.phpfreaks.com/topic/228946-passing-variable-between-two-functions/ Share on other sites More sharing options...
AbraCadaver Posted February 26, 2011 Share Posted February 26, 2011 function one() { $id = $this->two(); echo $id; } Link to comment https://forums.phpfreaks.com/topic/228946-passing-variable-between-two-functions/#findComment-1180111 Share on other sites More sharing options...
MDanz Posted February 27, 2011 Author Share Posted February 27, 2011 i tried this and get this error.... Parse error: syntax error, unexpected T_RETURN in... <?php $newdb = new Database(); class Database { function one() { $id = $this->two(); echo $id; } function two() { $id = 9 return $id; } } ?> Link to comment https://forums.phpfreaks.com/topic/228946-passing-variable-between-two-functions/#findComment-1180198 Share on other sites More sharing options...
MDanz Posted February 27, 2011 Author Share Posted February 27, 2011 now the page is blank <?php $newdb = new Database(); $newdb->one; class Database { function one() { $id = $this->two(); echo $id; } function two() { $id = 9; return $id; } } ?> Link to comment https://forums.phpfreaks.com/topic/228946-passing-variable-between-two-functions/#findComment-1180202 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.