Jump to content

[SOLVED] problem with include(). Remember namespace


zota
 Share

Recommended Posts

Hi!

Sorry for being again with a silly question....
Look at that code:
 

<div pw-append="pageContent">
		
		<?php 
	
			//include("./scripts/_func.php");
			//include("./scripts/_func.php");
			
			function renderNav(PageArray $items) {
				blah, blah pasted code...
			}
			if($page->hasChildren) {
				echo renderNav($page->children);
			}

clumsy isn’t it? Here is the thing:
Function renderNav is defined on the file _func.php, so I tried  to include _func.php .
Then I get a php error - renderNav() is undefined! (what!?grrr)

Then, as you see, I duplicate the include line and run.
BUT got the php error  msg: "Can't redefine function renderNav()"  - What!? the f***g bastard already knew renderNav()! 

Then, I temporary gave up, commented out the include lines and did a copy + paste  the renderNav().
And, ugly enough, it works, sure.

What's wrong with my include?

Thanks

EDIT: solved thanks to LostKobrakai remark.  I forgot the <?php namespace ProcessWire; ?> thing

Edited by zota
give the solution
Link to comment
Share on other sites

19 minutes ago, LostKobrakai said:

_func.php and this file probably do have different namespaces (might be because of the compiler). \renderNav() !== \ProcessWire\renderNav().

You are right (of course you are). I prepended

<?php namespace ProcessWire;
?>

and works fine.
thanks again

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...