KenHorse Posted August 24, 2020 Share Posted August 24, 2020 Mon Aug 24, 2020 2:41 pm I'm using php_serial.class.php, called once require_once("php_serial.class.php"); and call it $serial: $serial = new phpSerial; The above are in a global.php file that sets up the serial com parameters. In another file, I include global.php that contains my other code to send and read from the class In a function, I pass the class: Function checkInput($serial){ And one in the Function: $read = $serial->readPort(); This throws an error: "PHP Fatal error: Uncaught Error: Call to a member function readPort() on string" If I do the $read outside of the Function, it doesn't throw the error so I assume I'm doing something wrong passing the class to the function? Quote Link to comment https://forums.phpfreaks.com/topic/311380-passing-class-to-function/ Share on other sites More sharing options...
requinix Posted August 24, 2020 Share Posted August 24, 2020 19 minutes ago, KenHorse said: If I do the $read outside of the Function, it doesn't throw the error so I assume I'm doing something wrong passing the class to the function? Correct. Apparently you're calling checkInput() with a string instead of a phpSerial object. Quote Link to comment https://forums.phpfreaks.com/topic/311380-passing-class-to-function/#findComment-1580933 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.