如何在代码中使用这个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。