我有一个构造函数。除了最后一部分,一切都有效。
class Article {
public $category;
public $title;
public $text;
public $intro;
public function __construct($category, $title, $text) {
$this->category = $category;
$this->title = $title;
$this->text = $text;
$this->intro = substr($this->text, 0, 40);
}
}
没有创建简介。
答案 0 :(得分:1)
它运作得很好:
<?php
class Article {
public $category;
public $title;
public $text;
public $intro;
public function __construct($category, $title, $text) {
$this->category = $category;
$this->title = $title;
$this->text = $text;
$this->intro = substr($this->text, 0, 40);
}
}
$test=new Article('a','b','A question is a linguistic expression used to make a request for information, or the request made using such an expression. The information requested may be provided in the form of an answer.');
echo $test->intro; //A question is a linguistic expression us