numaanc Posted July 29, 2009 Share Posted July 29, 2009 Hi All I've just registered - my first post In my 6+ years of developing software, I've never had to post a question online but I am so baffled by this, I need some help guys! I've got a class EnvDetails (storing the details of the environment i'm running my php in) and I'm trying to invoke a function like so <html xmlns="http://www.w3.org/1999/xhtml"> <!--... css imports etc --> <head> <title> My Page Title </title> </head> <?php session_start(); require_once ($_SERVER["DOCUMENT_ROOT"]."/scripts/envUtil.php"); ini_set('log_errors', true); $details = EnvDetails::getInstance(); if ($details->isLive()) { $fileLocation="qa.log.txt"; <!-- Other environment-specific stuff --> } ?> <body>...</body> My environemnt class : class EnvDetails { <!-- .... --> public $ENV; //Either QA or LIVE public function isLive() { return strcmp(self::$instance->ENV, "LIVE")==0; } } When I open the page in a browser, php parses up to this much $details = EnvDetails::getInstance(); if ($details-> Then the page itself has isLive() and the rest of my php code. It looks like the php parser doesn't like the arrow -> so it dumps out everything after but everything tells me this is how to call a function. Some help please? Thanks! Link to comment https://forums.phpfreaks.com/topic/168039-calling-php-function/ Share on other sites More sharing options...
fooDigi Posted July 29, 2009 Share Posted July 29, 2009 first off... i think your post got truncated... and you should always call session_start() before any output is sent to the browser... edit: ahh, never mind, you fixed the post... Link to comment https://forums.phpfreaks.com/topic/168039-calling-php-function/#findComment-886256 Share on other sites More sharing options...
numaanc Posted July 29, 2009 Author Share Posted July 29, 2009 Thanks for the reply but I'm still stuck on this Would really appreciate any help or pointers... Link to comment https://forums.phpfreaks.com/topic/168039-calling-php-function/#findComment-886274 Share on other sites More sharing options...
fooDigi Posted July 29, 2009 Share Posted July 29, 2009 try instantiating the class with this ... $details = new EnvDetails; instead of ... $details = EnvDetails::getInstance(); Link to comment https://forums.phpfreaks.com/topic/168039-calling-php-function/#findComment-886283 Share on other sites More sharing options...
Mark Baker Posted July 29, 2009 Share Posted July 29, 2009 I think it more likely that the server isn't parsing the page as php, but rendering it as straight html. <?php would be treated as a straight opening HTML tag (invalid of course, so simply not displayed) and the -> would correspond to the end of the tag... hence everything else after that point is displayed. Can you do a straight <?php phpinfo(); ?> ? Link to comment https://forums.phpfreaks.com/topic/168039-calling-php-function/#findComment-886308 Share on other sites More sharing options...
fooDigi Posted July 29, 2009 Share Posted July 29, 2009 sounds very probable.... i tried to duplicate his logic, and i receive an error right at isLive() right after the "->".... maybe errors aren't on, but that wouldn't explain it spitting out the php code... Link to comment https://forums.phpfreaks.com/topic/168039-calling-php-function/#findComment-886317 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.