SMFHacks.com

Modifications/Themes => General SMF Forum => Topic started by: shuban on February 20, 2017, 11:27:54 pm

Title: Strange SMF Behaviour when dealing with PHP classes
Post by: shuban on February 20, 2017, 11:27:54 pm
When I try loading a class inside an SMF template, i.e. index.template.php

Code: [Select]
include("/to_path_way/somefunction.class.php");
$equations = new phpequations();

 $context['equation'] = $equations->solve("x-y=-4
 x+z=8
 x-y-z=10");

And I print out  $context['equation'], it gives me hundreds of errors, but when I don't use anything SMF related, it works as it should.

What's the trick to getting classes to work with SMF's templates?
Title: Re: Strange SMF Behaviour when dealing with PHP classes
Post by: SMFHacks on February 20, 2017, 11:30:14 pm
Whats the error
Title: Re: Strange SMF Behaviour when dealing with PHP classes
Post by: shuban on February 20, 2017, 11:36:49 pm
Mostly all

PHP Notice:  Undefined variable: ...

The exact same code placed into /example.php works perfectly.
Title: Re: Strange SMF Behaviour when dealing with PHP classes
Post by: SMFHacks on February 21, 2017, 12:05:48 am
both have errors just smf is displaying those errors
Title: Re: Strange SMF Behaviour when dealing with PHP classes
Post by: shuban on February 21, 2017, 12:07:09 am
In /example.php, those errors don't exist.

Would it help to upload the class?

http://naveedurrehman.com/demo/phpequations/?page=demo#output
Title: Re: Strange SMF Behaviour when dealing with PHP classes
Post by: SMFHacks on February 21, 2017, 12:09:52 am
If you add ini_set("display_errors",1); to the other script they probably will show. On the very first line.
Title: Re: Strange SMF Behaviour when dealing with PHP classes
Post by: shuban on February 21, 2017, 12:11:27 am
You're right :-\

What's going on then?
Title: Re: Strange SMF Behaviour when dealing with PHP classes
Post by: SMFHacks on February 21, 2017, 12:32:34 am
SMF displays errors by default.
Index.php important
Code: [Select]
error_reporting(defined('E_STRICT') ? E_ALL | E_STRICT : E_ALL);
And sources/errors.php
Code: [Select]
// Ignore errors if we're ignoring them or they are strict notices from PHP 5 (which cannot be solved without breaking PHP 4.)
if (error_reporting() == 0 || (defined('E_STRICT') && $error_level == E_STRICT && (empty($modSettings['enableErrorLogging']) || $modSettings['enableErrorLogging'] != 2)))
return;
Title: Re: Strange SMF Behaviour when dealing with PHP classes
Post by: shuban on February 21, 2017, 12:33:35 am
So do you think the script is faulty or an SMF thing?
Title: Re: Strange SMF Behaviour when dealing with PHP classes
Post by: SMFHacks on February 21, 2017, 12:37:13 am
Script is faulty shouldn't have undefined errors.