PHP class - How to use

Asked

Viewed 330 times

-6

How to use a specific php class ?

For example:

<?php
class Torrent
{
    public function scrape(array $announce = [ ] , $hash_info = null)
    {

        $r = [
            'seeders'  => 0 ,
            'leechers' => 0
        ];

        foreach ( $announce as $an ) {

            $d = get_remote_peers($an , $hash_info);

            if ( isset($d['seeders']) ) {
                $r['seeders'] += $d['seeders'];
            }

            if ( isset($d['leechers']) ) {
                $r['leechers'] += $d['leechers'];
            }
        }

        return $r;
    }

}
?>

How do I use this class ?

I ran tests like this:

<?php

$meuObjeto = new Torrent();

$meuObjeto->scrape("$r"); 

?>

and so

<?php

$meuObjeto = new Torrent();

$meuObjeto->scrape("udp://fopen.demonii.com", 7C90CFEE93DE8C4FA04526DAA5CE530ADFB8DF6E); 

?>

unsuccessful...

Parse error: syntax error, Unexpected 'C90CFEE93DE8C4FA04526DAA5CE530' (T_STRING) in C: xampp htdocs gamepatch udpscrap.php on line 457

  • 4

    Place 7C90CFEE93DE8C4FA04526DAA5CE530ADFB8DF6E in quotes, as it is a string!

  • 8

    It scares me a question that is caused by syntax errors and not having much research effort to have 2 positive votes.

  • I believe the phrase Parse error: syntax error at the beginning of the error should mean something...

1 answer

4

Observing your code I could notice the following error in line 3 of this code

<?php
$meuObjeto = new Torrent();
$meuObjeto->scrape("udp://fopen.demonii.com", 7C90CFEE93DE8C4FA04526DAA5CE530ADFB8DF6E); 
?>

The second parameter of the method scape() need quotes (single or double, whatever) so that the format of this parameter becomes .
So he should stay that way:

<?php
$meuObjeto = new Torrent();
$meuObjeto->scrape("udp://fopen.demonii.com", "7C90CFEE93DE8C4FA04526DAA5CE530ADFB8DF6E"); 
?>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.