Задать вопрос
@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;}}
  • Вопрос задан
  • 94 просмотра
Подписаться 1 Простой Комментировать
Помогут разобраться в теме Все курсы
  • Skillbox
    Веб-разработчик на PHP
    9 месяцев
    Далее
  • Хекслет
    PHP-разработчик
    10 месяцев
    Далее
  • Нетология
    Веб-разработчик с нуля: профессия с выбором специализации
    14 месяцев
    Далее
Решения вопроса 1
@IS-Builder
~ PHP-8 & REGEXP - This is a really powerful kit ~
igordata1 это же код из книги Зандстры, там всё описано. Зачем сюда его копипастить, если тут напишут точно такие же пояснения? Читайте и перечитывайте источник, до полного понимания.
Ответ написан
Пригласить эксперта
Ответы на вопрос 1
@Kostik_1993
Web Developer
Это потому что ты неуч. Это основы основ синтаксиса. Советую закрыть редактор и открыть доку PHP
Этот метод просто строит строку и возвращает ее.
Оператор .= объединяет строки

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

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

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

Похожие вопросы
FoodSoul Калининград
от 180 000 до 250 000 ₽
IT-Spirit Москва
от 230 000 до 320 000 ₽
от 200 000 до 290 000 ₽