@igordata1

Мне непонятна работа этого метода getSummaryLine?

class ShopProduct
{
public $numPages;
public $playLength;
public $title;
public $producerMainName;
public $producerFirstName;
public $price;
public function __ construct(
string $title,
string $firstName,
string $mainName,
float $price,
int $numPages = 0,
int $playLength = 0
) {
$this->title = $title;
$this->producerFirstName = $firstName;
$this->producerMainName = $mainName;
$this->price = $price;
$this->numPages = $numPages;
$this->playLength = $playLength;
}
public function getProducer()
{
return $this->producerFirstName
. $this->producerMainName;

public function getSummaryLine()
{
$base
= ” { $this->title} ( { $this->producerMainName),
$base .= ” { $this->producerFirstName}
return $base;}}

<?php
namespace popp\ch03\batch11;

/* listing 03.30 */
class ShopProduct
{
    public $numPages;
    public $playLength;
    public $title;
    public $producerMainName;
    public $producerFirstName;
    public $price;
/* /listing 03.30 */
    public $type="book";
/* listing 03.30 */

    public function __construct(
        string $title,
        string $firstName,
        string $mainName,
        float  $price,
        int    $numPages = 0,
        int    $playLength = 0
    ) {
        $this->title             = $title;
        $this->producerFirstName = $firstName;
        $this->producerMainName  = $mainName;
        $this->price             = $price;
        $this->numPages          = $numPages;
        $this->playLength        = $playLength;
    }

    public function getNumberOfPages()
    {
        return $this->numPages;
    }

    public function getPlayLength()
    {
        return $this->playLength;
    }

    public function getProducer()
    {
        return $this->producerFirstName . " "
            . $this->producerMainName;
    }
/* /listing 03.30 */

    public function setType(string $type)
    {
        $this->type=$type;
    }
/* listing 03.31 */

    public function getSummaryLine()
    {
        $base  = "{$this->title} ( {$this->producerMainName}, ";
        $base .= "{$this->producerFirstName} )";
        if ($this->type == 'book') {
            $base .= ": page count - {$this->numPages}";
        } elseif ($this->type == 'cd') {
            $base .= ": playing time - {$this->playLength}";
        }
        return $base;
    }
/* /listing 03.31 */
/* listing 03.30 */
}
/* /listing 03.30 */


Мне непонятна работа этого метода getSummaryLine?

public function getSummaryLine()
{
$base
= ” { $this->title} ( { $this->producerMainName),
$base .= ” { $this->producerFirstName}
return $base;}}
  • Вопрос задан
  • 91 просмотр
Решения вопроса 1
@IS-Builder
~ PHP-8 & REGEXP - This is a really powerful kit ~
igordata1 это же код из книги Зандстры, там всё описано. Зачем сюда его копипастить, если тут напишут точно такие же пояснения? Читайте и перечитывайте источник, до полного понимания.
Ответ написан
Пригласить эксперта
Ответы на вопрос 1
@Kostik_1993
Web Developer
Это потому что ты неуч. Это основы основ синтаксиса. Советую закрыть редактор и открыть доку PHP
Этот метод просто строит строку и возвращает ее.
Оператор .= объединяет строки

$text = 'Вася';
$text .= ' Пупкин';
Вернет 'Вася Пупкин'

P.S. все твои вопросы от незнания языка. Иди учи потом берись писать
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы