unemployment Posted July 6, 2011 Share Posted July 6, 2011 Why doesn't the second option work? This works... $number = 2; $data = new user_info(); $data->info_data($number); This doesn't... $data = new user_info(); $data->info_data(2); Link to comment https://forums.phpfreaks.com/topic/241259-cant-pass-number-as-oop-parameter/ Share on other sites More sharing options...
xyph Posted July 6, 2011 Share Posted July 6, 2011 Yes, it does. Link to comment https://forums.phpfreaks.com/topic/241259-cant-pass-number-as-oop-parameter/#findComment-1239254 Share on other sites More sharing options...
AyKay47 Posted July 6, 2011 Share Posted July 6, 2011 Why doesn't the second option work? This works... $number = 2; $data = new user_info(); $data->info_data($number); This doesn't... $data = new user_info(); $data->info_data(2); I don't understand how that wouldn't work...setting a variable to the int 2 is the same as passing the actual int 2...maybe something in your class itself? Link to comment https://forums.phpfreaks.com/topic/241259-cant-pass-number-as-oop-parameter/#findComment-1239258 Share on other sites More sharing options...
KevinM1 Posted July 6, 2011 Share Posted July 6, 2011 More to the point, what does "doesn't work" actually mean? Link to comment https://forums.phpfreaks.com/topic/241259-cant-pass-number-as-oop-parameter/#findComment-1239260 Share on other sites More sharing options...
unemployment Posted July 6, 2011 Author Share Posted July 6, 2011 My misunderstanding I was trying to pass it by reference. I was just trying to learn what by reference actually does. Can anyone enlighten me. class user_info { public function info_data(&$number){ $number *= 3; echo $number; } } $data = new user_info(); $data->info_data(2); Link to comment https://forums.phpfreaks.com/topic/241259-cant-pass-number-as-oop-parameter/#findComment-1239262 Share on other sites More sharing options...
AyKay47 Posted July 6, 2011 Share Posted July 6, 2011 http://php.net/manual/en/language.references.pass.php Link to comment https://forums.phpfreaks.com/topic/241259-cant-pass-number-as-oop-parameter/#findComment-1239265 Share on other sites More sharing options...
xyph Posted July 6, 2011 Share Posted July 6, 2011 <?php $value = 5; double( $value ); echo $value; // outputs 10 function double( &$num ) { $num = $num * 2; } ?> Link to comment https://forums.phpfreaks.com/topic/241259-cant-pass-number-as-oop-parameter/#findComment-1239266 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.