这在init.php上运行得很好
include 'models/m_app.php';
include 'views/v_app.php';
include 'controllers/c_app.php';
但是spl_autoload_register()不起作用
spl_autoload_register(function ($class) {
include 'models/' . $class . '.class.php';
include 'views/' . $clas
我使用PHP7.1.0。
假设我们有一个特性,我们在类中使用它并重命名导入的方法:
trait T
{
public function A() {
echo ".";
}
}
class C
{
use T {
A as B;
}
}
$c = new C();
$c->B();
$c->A(); // Why does it work?
为什么PHP仍然允许我使用旧的方法名(在本例中是A)?
这真的很痛苦,因为在更复杂的例子中,您不能依赖于方法重命名--因此您可以意外地收到“不兼容声明”错误:
c
我的run.php文件包含
use Installer\App;
include 'app/Installer/App.php';
App::instance()->init($_REQUEST);
app.php包含两个函数instance()和init($param = array())。
为什么一个函数被另一个函数调用??
我的代码.:
<?php
namespace Application\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
class IndexController extends AbstractActionController
{
public function init()
{
echo 'init worked';
}
public function indexAction()
我有四个文件: functions.php、lang.php、init.php和index.php。
functions.php
function loadLanguage()
{
include_once("lang.php");
}
lang.php
$LANG = array(
"SOMETEXT" => "This is a random text"
);
init.php
include_once("functions.php");
loadLanguage();
index.php
include
我最近为这个API做了一个api,我做了一个子域,但是它破坏了我的php文件,包括
include $_SERVER['DOCUMENT_ROOT'].'/core/init.php';
现在我使用的子域是api.website.com,当我试图包含它给出子域的根时,我需要从website.com中包含一些东西,
当我尝试包含init.php时,我得到
Warning: include(/home/website/public_html/API/core/init.php): failed to open stream: No such file or dire
我在Database.php里有这些
class Database
{
private $dbname = 'auth';
private $db_instance;
public function __construct($q)
{
if(!$this->db_instance)
$this->db_instance = new SQLite3($q);
}
private function init()
{
if(!$this->db_inst
C:\程序文件(x86)\Zend\Apache2\htdocs\zf2-tutorial\public\index.php:
<?php
/**
* This makes our life easier when dealing with paths. Everything is relative
* to the application root now.
*/
chdir(dirname(__DIR__));
我正在使用Smarty和PHP创建一个简单的类似博客的CMS。我遇到的问题是,我似乎无法启动会话。
我有一个包含以下内容的init.php文件:
<?php
session_start();
// Mudar a path do PHP para podermos fazer include das
// bibliotecas mais facilmente
set_include_path(".:./lib");
// Fazer include do MDB2
require_once ('MDB2.php');
(.
我正在尝试添加自定义端点(自定义端点“是指WP未识别为标准URL的任意URL,如permalink之类)。我使用WordPress插件样板"“。
我想在自定义端点上发送API请求。我创建了一个新的类文件来注册端点,并将这个类文件包含在插件激活方法中,并调用add_action钩子,但是它不起作用。
在包含文件夹中创建一个新的类-rigal-定制-Endpoint.php文件。
<?php
class Rigal_custom_Endpoint {
private static $initiated = false;
public static function
我收到了这个错误。
Error (flymake): Flymake: Failed to launch syntax check process 'php' with args (-f test_flymake.php -l): Searching for program: no such file or directory, php. Flymake will be switched OFF
我使用的是windows7和emacs24GNU emacs 24.1.1 (i386-mingw-nt6.1.7601),有一篇文章强调了这个错误,但它指的是在linux中检查/et
我有这样的情况:
/
index.php
/init (folder)
init.php (of course inside this file i use require_once for db/function/and whatever you want to put inside)
/layout_parts (folder)
header.php (and others common parts are inside this folder)
/my_space (folder inside layout parts)
my_file.p
我有一个我正在研究的系统:
abstract class Model {
static $table = "";
abstract static function init();
public static function getById() {
$table = self::$table;
}
}
class Model_user extends Model {
static function init() {
self::$table = "users";
}
}
cla
我有一些课程
/library/QPF/Loader.php
namespace QPF;
class Loader
{
protected static $loader = null;
public function __construct()
{
spl_autoload_register('QPF\Loader::_autoload');
}
public static function init()
{
if (null === self::$loader) {
我有3份文件如下:
controller.php
class inject{
public function __construct(){
echo 'I say';
}
}
model.php
class say extends inject{
public function init(){
echo ' hello ';
$this->otherFunction();
}
public function otherFunction(){
//pare
随着时间的推移,我一直在做一些研究,并想知道是否可以像C#那样在PHP类中使用属性,我已经找到了这些问题,其中有一些很好的答案和指针,但并没有真正帮助我:
虽然,正如我所说,这些都给出了很好的答案,但我仍然不能下决心,例如,我想要做一些事情,例如:
class Foo
{
public $bar
{
get { return $this->bar; }
set { $this->bar = value; }
}
}
但我做不到!
在PHP的约束下,最好的方法是什么?
我能想到的是:
class user
我有一个Model类:
// core/Model.php
namespace Core;
class Model {
protected static $class_name;
// This methods needs to be called when a child class is autoloaded:
protected static function init() {
// Set the classname of the child class using late static binding
static
我正在为我的项目创建一个头像上传系统。我似乎无法绕过这个错误……
以下是代码
public function update_avatar(Request $request){
// Handle the user upload of avatar
if($request->hasFile('avatar')) {
$avatar = $request->file('avatar');
$filename = time() . '.' . $avatar->getClient
是否有可能从基类构造函数调用扩展类方法?
下面是我想要做的一个例子:
<?php
class SomeController extends Controller {
public function init() {
echo "lol";
}
}
class Controller {
public function __construct() {
// do something to call init() in SomeController.
}
}
只是想知道像这样的事情是可能的。