PHP: how to access variables inside a function that have been declared outside of it?

Posted by Chris on Stack Overflow See other posts from Stack Overflow or by Chris
Published on 2012-07-06T21:11:47Z Indexed on 2012/07/06 21:15 UTC
Read the original article Hit count: 224

Filed under:
|
|
|

Please, I am very new and have not been confronted with OOP and all this related stuff, which I guess may be related to this issue (public, private, ...). So, any help and suggestions are very appreciated! :)

At the very beginning of each page I include a file that starts the SESSION etc, lets call it session.php. In this file session.php, I include a file that contains a function, let's call it function1.php, because I need the function to be available in session.php.

However, later in the main page I also include function2.php which needs to access variables set in session.php, so I additionally tried to include session.php in function2.php.

The problem is that an error occurs as function1 will be declared multiple times...

Fatal error: Cannot redeclare function1() (previously declared in ...

So, what would be a more elegant and clean(er) solution for this? How could you solve it?

Basically, I'd need to access variables inside a function that have been included in the main page before...

Thank you very much in advance!

© Stack Overflow or respective owner

Related posts about php

Related posts about function