Jump to content

Passing class to Function


KenHorse

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.