Solved

Not sure how to progress this PHP problem

Posted on 2012-03-21
1
218 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 110

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How do I show metrics with PHP or Javascript 6 46
How to get this library to work load? 8 37
i am unable to add data to mysql database 6 48
Make login page safer 3 30
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

685 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