Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在代码中使用这个PHP类?_Php - Fatal编程技术网

如何在代码中使用这个PHP类?

如何在代码中使用这个PHP类?,php,Php,我的目录结构: bencode_test- |--> BEncode.php |--> bencode_test.php |--> ubuntu-15.10-desktop-amd64.iso.torrent my code: <?php require 'BEncode.php'; $bcoder = new BEncode(); $torr

我的目录结构:

bencode_test-
            |--> BEncode.php
            |--> bencode_test.php
            |--> ubuntu-15.10-desktop-amd64.iso.torrent

my code:
    <?php
        require 'BEncode.php';
        $bcoder = new BEncode();
        $torrent = $bcoder->bdecode( File::get('ubuntu-15.10-desktop-amd64.iso.torrent'));
        var_dump($torrent);
    ?>
有人能告诉我我做错了什么吗

调用类应该是这样的

你的文件夹看起来像这样

bencode_test # calling function from here
            |--> BEncode.php
            |--> bencode_test.php
            |--> ubuntu-15.10-desktop-amd64.iso.torrent
index.php # code
所以在BEncode.php中

public function myName($value)
{
    $name = "My Name is :".$value;
    return $name
}
所以inside.php

<?php
    require './bencode_test/BEncode.php';
    $bcoder = myName("Ab");
    //$torrent = $bcoder->bdecode( File::get('ubuntu-15.10-desktop-amd64.iso.torrent'));
    //var_dump($torrent);
?>

调用类应该是这样的

你的文件夹看起来像这样

bencode_test # calling function from here
            |--> BEncode.php
            |--> bencode_test.php
            |--> ubuntu-15.10-desktop-amd64.iso.torrent
index.php # code
所以在BEncode.php中

public function myName($value)
{
    $name = "My Name is :".$value;
    return $name
}
所以inside.php

<?php
    require './bencode_test/BEncode.php';
    $bcoder = myName("Ab");
    //$torrent = $bcoder->bdecode( File::get('ubuntu-15.10-desktop-amd64.iso.torrent'));
    //var_dump($torrent);
?>

位于命名空间中。必须在文件开头添加类的别名::

<?php
use Bhutanio\BEncode\BEncode;
?>

因此,总而言之:

<?php
use Bhutanio\BEncode\BEncode;
require 'BEncode.php';
$bcoder = new BEncode();
$torrent = $bcoder->bdecode( File::get('ubuntu-15.10-desktop-amd64.iso.torrent'));
var_dump($torrent);
位于命名空间中。必须在文件开头添加类的别名::

<?php
use Bhutanio\BEncode\BEncode;
?>

因此,总而言之:

<?php
use Bhutanio\BEncode\BEncode;
require 'BEncode.php';
$bcoder = new BEncode();
$torrent = $bcoder->bdecode( File::get('ubuntu-15.10-desktop-amd64.iso.torrent'));
var_dump($torrent);

谢谢你,阿卜杜拉。你能告诉我为什么创建者在他的README.md中使用了新操作符吗?谢谢,Abdulla。你能告诉我为什么创建者在他的README.md中使用了新操作符吗?谢谢你的解释,Pemap。谢谢你的解释,Pemap。