Welcome Guest, Not a member yet? Register   Sign In
User class not found
#1

Hello,
in the folder *application/libraries* I installed a script "Utilities.php", with a class "Utilities".
Instancing the class is no problem, also reflection displays all methods.
but when I pass the object to the constructor of another class,
I get the strange error

Severity: Error
Message: Class 'CI_Utilities' not found
Filename: core/Common.php
Line Number: 196

Why does CI create a class CI_Utilities from a user class?
What is wrong here?

thanx for your help, Helmut
Reply
#2

(This post was last modified: 11-02-2015, 08:05 AM by sv3tli0.)

How do you load this class in your code? with load->library('Utilities') or autoload ?

1 advice - to prevent duplication of CI Class names try adding prefix or suffix to your class : Utilities_library..
Best VPS Hosting : Digital Ocean
Reply
#3

(11-02-2015, 08:02 AM)sv3tli0 Wrote: How do you load this class in your code? with load->library('Utilities') or autoload ?

with:
$this->load->library('Utilities');
Reply
#4

(11-02-2015, 08:02 AM)sv3tli0 Wrote: 1 advice - to prevent duplication of CI Class names try adding prefix or suffix to your class : Utilities_library..

This should only be done if you want to extend native CI-Libraries.
https://ellislab.com/codeigniter/user-gu...aries.html

Having looked into the sourcecode of Common.php, I have the impression that there is a bug.
Reply
#5

(This post was last modified: 11-05-2015, 12:40 AM by Martin7483.)

How and to which class are you passing the utilities or user object?

Did a quick test with two libraries. One I called Utilities and the second one Test.
I then did this:
PHP Code:
$this->load->library('Utilities');
$this->load->library('Test', array($this->utilities)); 

Got 0 errors with this. So Utilities is not a reserved name within CI nore does CI change it in anyway that I chould see.
Reply
#6

(11-04-2015, 09:14 AM)Martin7483 Wrote: How and to which class are you passing the utilities or user object?

Did a quick test with two libraries. One I called Utilities and the second one Test.
I then did this:
PHP Code:
$this->load->library('Utilities');
$this->load->library('Test', array($this->utilities)); 

Got 0 errors with this. So Utilities is not a reserved name within CI nor does CI change it in anyway that I chould see.

Thanks,now I see that the problem is in the instanciation of the other class (Test in your example), which I did not perform correctly.
But now after the commands

$this->load->library('Test', array($this->utilities)); //here no error occurs
--
$vars = get_object_vars($this->Test);
var_dump($vars);

I get the error
Message: Undefined property: Test::$Test
and
Message: get_object_vars() expects parameter 1 to be object, null given
Reply
#7

(This post was last modified: 11-05-2015, 04:45 AM by pdthinh.)

(11-05-2015, 04:30 AM)helmut Wrote:
(11-04-2015, 09:14 AM)Martin7483 Wrote: How and to which class are you passing the utilities or user object?

Did a quick test with two libraries. One I called Utilities and the second one Test.
I then did this:
PHP Code:
$this->load->library('Utilities');
$this->load->library('Test', array($this->utilities)); 

Got 0 errors with this. So Utilities is not a reserved name within CI nor does CI change it in anyway that I chould see.

Thanks,now I see that the problem is in the instanciation of the other class (Test in your example), which I did not perform correctly.
But now after the commands

$this->load->library('Test', array($this->utilities));           //here no error occurs
--
$vars = get_object_vars($this->Test);
var_dump($vars);

I get the error
Message: Undefined property: Test::$Test
and
Message: get_object_vars() expects parameter 1 to be object, null given

As far as I know, you should use $this->test (in lower case)
Also get_object_vars and var_dump should be called outside the Test class.
Reply
#8

(11-05-2015, 04:37 AM)pdthinh Wrote: As far as I know, you should use $this->test (in lower case)

@pdthinh is correct it should be
PHP Code:
$vars get_object_vars($this->test); // test in lower case! 
Reply
#9

(11-05-2015, 04:48 AM)Martin7483 Wrote:
(11-05-2015, 04:37 AM)pdthinh Wrote: As far as I know, you should use $this->test (in lower case)

@pdthinh is correct it should be
PHP Code:
$vars get_object_vars($this->test); // test in lower case! 

Unfortunately the error occurs in either version, lower AND upper case Confused
Reply
#10

Have you found a solution?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB