Solved

Not sure how to progress this PHP problem

Posted on 2012-03-21
1
217 Views
Last Modified: 2012-03-21
I'm trying to connect to an API using the code I was given for the purpose below. It fails on line 9 with the error:-

"Fatal error: Using $this when not in object context"

Can someone help me understand how to resolve this?

Thanks


function get_response($res) {
    $size_packed = fread($res, 4);
    if(strlen($size_packed) == 0) { return; }
    $size = unpack("N", $size_packed);
    // This works around PHP's fread() capping at 8192 bytes
    $out = "";
    $last = "";
    for($s = $size[1]-4; $s>0; $s-=strlen($last)) {
        $last = fread($this->res, $s);
        $out.=$last;
    }
    return $out;
}

$api_host = "api.domain.com";
$api_port = 1701;
$clID = "MyID";
$pw = "MyPassword";

$res = fsockopen("tls://" . $api_host, $api_port);

get_response($res);

Open in new window

0
Comment
Question by:cescentman
1 Comment
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 37748163
$this is a reserved word in PHP.

You might try changing line 9 to something like this:

$last = fread($res, $s);
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Cookie not unsetting 7 27
Logic behind "best rated" calculation 11 31
What does this formatting equate to? 7 18
$_SERVER Variable question 31 29
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question