public function addSubject(\SplSubject $subject, $subjectName = null): self
    {
        if ($subjectName === null) {
            $subjectName = get_class($subject);
        }
        
        if (
            array_key_exists($subjectName, $this->subjectList) &&
            $this->subjectList[$subjectName] !== $subject
        ) {
            throw new \Exception(
                'A subject with the name '.$subjectName.' already exist.',
                self::ERR_ADD_SUBJECT_ALREADY_EXIST
            );
        }
        
        $this->subjectList[$subjectName] = $subject;
        
        return $this;
    }
public function addSubject(\SplSubject $subject, $subjectName = null): self
    {
        if ($subjectName === null) {
            $subjectName = get_class($subject);
        }
        
        if (
            array_key_exists($subjectName, $this->subjectList) &&
            $this->subjectList[$subjectName] !== $subject
        ) {
            throw new \Exception(
                'A subject with the name '.$subjectName.' already exist.',
                self::ERR_ADD_SUBJECT_ALREADY_EXIST
            );
        }
        
        $this->subjectList[$subjectName] = $subject;
        
        return $this;
    }
public function addSubject ( \ SplSubject $ subject , $ subjectName = null ) : self { if ( $ subjectName === null ) { $ subjectName = get_class ( $ subject ) ; } if ( array_key_exists ( $ subjectName , $ this -> subjectList ) && $ this -> subjectList [ $ subjectName ] !== $ subject ) { throw new \ Exception ( 'A subject with the name ' . $ subjectName . ' already exist.' , self :: ERR_ADD_SUBJECT_ALREADY_EXIST ) ; } $ this -> subjectList [ $ subjectName ] = $ subject ; return $ this ; }
Add a new subject to the list

@param \SplSubject $subject The new subject to add
@param string|null $subjectName (default null) The subject name, if null,
the name of the class will be used

@return $this
Add a new subject to the list