gpt4 book ai didi

php oo : why does this code prints only the first objects?

转载 作者:行者123 更新时间:2023-12-03 19:14:32 25 4
gpt4 key购买 nike

<?php
//firt class of eitay

class hello
{
//hello word.
public $first = 'hello world';

public function first_method()
{
$a = 1;
$b = 2;
$c = $a + $b;
return $c;
return $this->first;
}
}

$momo = new hello();
print $momo->first_method();

最佳答案

它只打印 $c 因为函数在那之后返回。当您返回一个函数时(在本例中您 return $c),它将停止执行并返回到调用函数。

关于php oo : why does this code prints only the first objects?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12228063/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com