Solved

Not sure how to progress this PHP problem

Posted on 2012-03-21
1
214 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 108

Accepted Solution

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

You might try changing line 9 to something like this:

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

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

771 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now