Welcome Guest, Not a member yet? Register   Sign In
Weird problems, redeclaring a class O_o
#1

[eluser]moodh[/eluser]
Hi, I created a library named Foo, and tried loading it in a controller named Foo, isn't this possible? I can't find anything forbidding it in the user guide, but I get
Fatal error: Cannot redeclare class Foo in /var/www/wip/application/foo/libraries/Foo.php on line 7
(line 7 is 'class Foo {'

Sure I can use some other name but that just seems weird as nothing's said about this issue.
Any ideas?
#2

[eluser]jedd[/eluser]
Foo as a reserved word? Whodathunkit.

The problem, happily, is more related to the fact that you're attempting to have two classes called the same thing - and you just can't do that.

You can't have a library class with the same name as a controller class, in the same way that your controller class name can't be the same as your model class name. Are you seeing a trend here? Wink Class names must be unique.
#3

[eluser]wiredesignz[/eluser]
Try reading the PHP user guide as well.

http://php.net

EDIT:
Plus what Jedd said. Tongue
#4

[eluser]Dam1an[/eluser]
I'm not sure if it needs to be explicitly declared in the user guide, as it's nothing CI specific, it's a standard PHP error.

Once PHP introduces namespaces this won't be an issue, but until then, you either need to name the library differantly or the controller differantly.
It's the same with models, which is why most peopea ppend the _model suffix

edit: I step away from this thread for 10 seconds half way through posting, and 2 people sneak in?
edit 2: Plus what the other 2 said Tongue
#5

[eluser]moodh[/eluser]
Thanks for the replies =)
#6

[eluser]sherwoodforest[/eluser]
I got a similar the error when I called the same view more than once
#7

[eluser]Dam1an[/eluser]
[quote author="sherwoodforest" date="1249336173"]I got a similar the error when I called the same view more than once[/quote]

Now that is a wierd one, cause I assume you don't declare a class in the view? Want to show us some code?
#8

[eluser]sherwoodforest[/eluser]
I had the view (v_comreportgroup) called in the controller then again in another view(v_comreportheader)

I did't declare any classes in my view just a bunch of functions
that depending on the data output rows


I cant easily show the code next time I manage to get the error I will be happy to show the code.
#9

[eluser]Dam1an[/eluser]
Why are you declaring a bunch of functions in your views? They should probably be in a helper or library
Was the similar error that you where getting along the lines of "Cannot redeclare function xyz in filename.php"
#10

[eluser]sherwoodforest[/eluser]
why I had functions in my views.
each function handled the display of a row in a table, depending on the data different row were needed to be displayed and different fields.
For example one function handled the header row of the table
another handled the display if the lead had been sold
another handled the display if the lead had been retired but not sold
another handled the display if the lead was not retired yet.
I understood helper should be used sparingly and that they were for things like data cleaning and standardization like (making sure that phone numbers look like 800-555-1212 instead of (800) 555-1212 or 8005551212). I didn't think that they were for formating display elements.

yes, this was the similar error that I got

I am a self taught programmer.
perhaps my understanding of the CMV approach is incomplete. It was my understanding that you should put the display logic in the view and put the business logic in the the controller and the database logic in the models. So that is what I was doing I also had one view that was calling different views with all the parts of the end page. I also have struggled with the scope of objects much of my debugging is me discovering that I have missunderstood the scope or trying to treat object as arrays and arrays as objects. I have been very impressed with the quality of the CI forms and I am learning the right words to search and find answers.
For example yesterday I spent 1 hour trying to figure out why a image was displaying in firefox but not in IE, only to learn that it was a CMYK jpg. It didn't occur to me that firefox would display a CMYK jpg but I guess some one of the benefits to opensource projects is that common problems get things built to fix them. B




Theme © iAndrew 2016 - Forum software by © MyBB