Brady Pacha
Brady Pacha

Reputation: 313

CakePHP 3: Exception not Found

I've written several placeholder functions in my User model. All I want them to do is throw the NotImplementedException() provided by CakePHP. The function is nice and simple and I have tried it several different ways.

public function canConvert() {
    throw new NotImplementedException();
}

Error:Class 'App\Model\Entity\NotImplementedException' not found

public function canConvert() {
    throw new \NotImplementedException();
}

Error:Class 'NotImplementedException' not found

The only way I could find to do this was this way.

public function canConvert() {
    throw new \Cake\Network\Exception\NotImplementedException();
}

I tried to do a use Cake\Network\Exception; and the top and just throw a NotImplementedException() but that didn't work.

Upvotes: 3

Views: 1563

Answers (1)

M. Eriksson
M. Eriksson

Reputation: 13635

If you just do

use Cake\Network\Exception; 

you've only imported the namespace, not the classes under it. To reference a class under that namespace, you would then need to do:

throw new Exception\NotImplementedException();

PHP doesn't automatically import all classes under a namespace.

Read more in the manual: http://php.net/manual/en/language.namespaces.importing.php

Upvotes: 8

Related Questions