首先,让我向您展示我的代码示例:
<?php
class Example
{
public $name;
public function name(string $name)
{
if($name) $this->name = $name;
else throw new Exception('An argument is required.');
return $this;
}
public function in($name = false, $setting = true)
{
if($name) return $this::anotherMethod($name, 'in', $setting);
elseif($this->name) return $this::anotherMethod($this->name, 'in', $example);
}
}
我需要使用这些方法,例如:
<?php
$example = new Example;
echo $example->name('A Name Here')->in(false);
// OR / AND
$example = new Example;
echo $example::in('A Name Here', false);
所以我的问题是,我不能同时使用这些方法,因为首先我什至不知道是否可以将方法同时用作静态方法和其他方法,其次称为“in”的方法的参数是冲突的。如果我尝试第一个示例,“false”将取代“name”参数。我需要一种以两种方式使用这些方法的方法,两个示例。
现在,我正在看着屏幕,我无法集中注意力和理解任何东西,所以有人可以帮帮我吗?互联网结果和我的大脑没有帮助。