首页 > 解决方案 > php在尝试调用方法后输出代码

问题描述

我正在尝试重新创建 laravel 雄辩的 ORM。在我尝试调用一个类的方法后,php 会打印调用背后的代码。我使用作曲家和命名空间。也许知道我使用 xampp 很重要?!

这是我的代码

索引.php

<?
namespace com;

require_once __DIR__ . '/vendor/autoload.php';


use com\config\Conf;
use com\db\Table;
use com\db\dataTypes\INTEGER;
use com\Connectors\MySqlConnector;

$DB_HOST = Conf::$DB_HOST;
$DB_PORT = Conf::$DB_PORT;
$DB_USER = Conf::$DB_USER;
$DB_PASSWORD = Conf::$DB_PASSWORD;
$DB_NAME = Conf::$DB_NAME;

$connector = new MySqlConnector($DB_HOST,$DB_PORT,$DB_USER,$DB_PASSWORD,$DB_NAME);

$t1 = new Table("table1");
$age = new INTEGER("age");

//affected call
$age = $age -> primary() -> unsigned();


$counting = new INTEGER("counting");
$counting = $counting->nullable(false)->defaultValue(18);
$t1->addData($age);
$t1->addData($counting);

$connector->addTable($t1);
$connector->registerTables();

我已经用“//affected call”标记了代码的一部分。

整数.php

<?
namespace com\db\dataTypes;

use com\db\dataTypes\DataType;
use com\config\Conf;

class INTEGER extends DataType{

    
    private int $defaultValue = 0;
    private bool $unsigned = false;

    function __construct(string $col) {
        $this->column = $col;
    }
    //code

    public function primary() : INTEGER {
        $this->isPrimaryKey = true;
        return $this;
    }

    public function unsigned() : INTEGER {
        $this->unsigned = true;
        return $this;
    }
    //code
}

输出看起来像这样

primary() -> unsigned(); $counting = new INTEGER("counting"); $counting = $counting->nullable(false)->defaultValue(18); $t1->addData($age); $t1->addData($counting); $connector->addTable($t1); $connector->registerTables();

我不知道它是否有帮助,但这是我的composer.json

{
    "autoload": {
        "psr-4": {
            "com\\": "",
            "com\\config\\": "config/",
            "com\\db\\": "db/",
            "com\\db\\dataTypes\\": "db/dataTypes/",
            "com\\Connectors\\": "Connectors/"
        }
    }
}

标签: phpnamespacescomposer-php

解决方案


推荐阅读