Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Not sure how to progress this PHP problem

Posted on 2012-03-21
1
Medium Priority
?
222 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
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…
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.
Suggested Courses

618 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