0

First let me say I'm a beginner in PHP, specifically PHP Object-oriented programming.

I'm working on a V7.0.9 dolphin version.http://www.boonex.com/dolphin

While I'm trying to include a class.php from a 3rd-part developer I work with

<?php
include_once ('modules/developer/configure/classes/class.php');

I get this error :

Warning: include_once(modules/developer/configure/classes/ClassExample.php): failed to open stream: No such file or directory in /var/www/vhosts/mysite.com/httpdocs/dolphin/inc/classes/BxDolPageView.php(612) : eval()'d code on line 2
Warning: include_once(): Failed opening 'modules/developer/configure/classes/ClassExample.php' for inclusion (include_path='.:') in /var/www/vhosts/mysite.com/httpdocs/dolphin/inc/classes/BxDolPageView.php(612) : eval()'d code on line 2
Fatal error: Class 'ClassExample' not found in /var/www/vhosts/mysite.com/httpdocs/dolphin/inc/classes/BxDolPageView.php(612) : eval()'d code on line 6

I'm trying to figure out where is the problem... does it comes from Boonex? or is it linked to my server configuration? I really don't know where to begin to resolve...

Thx in advance for your kind help if you get knowledge on it

[EDIT] I omit to say that I'm writing my code inside PHP block, on the news homepage. Initial HTML blocks have been customised in order to accept PHP.

CodeZombie
  • 5,367
  • 3
  • 30
  • 37
  • you should include your files as this: `include_once(__DIR__ . "path/to/root/of/your/site/modules/developer/configure/classes/class.php");` \_\_DIR\_\_ is the folder path of the php file where you write \_\_DIR\_\_. – Pierre Emmanuel Lallemant Oct 30 '13 at 09:55
  • I tried and failed : Boonex leave the __DIR__information of my code! (I omit to say that I'm writing my php code in block, on the news homepage) –  Oct 30 '13 at 10:12
  • @PierreEmmanuelLallemant forgot a "/" : `include_once(__DIR__ . "/path/from/root/of/your/site/modules/developer/configure/classes/class.php");` – Asenar Oct 30 '13 at 10:18
  • Same issue: dolphin not allow me to use the __DIR__ constant –  Oct 30 '13 at 10:21
  • I'm pretty sure you screwed things up with your customization of the HTML blocks to accept PHP. The error messages mentions "eval()'d code". I guess you added support for PHP by using the `eval()` function. Check there first... – CodeZombie Oct 30 '13 at 10:31
  • Actually the eval() function is internal to dolphin... it refers to the BxDolPageView.php, which is very very official. –  Oct 30 '13 at 10:34
  • are you sure you need to use "include_once" ? Maybe dolphin provide a custom function to load this class. I think you could find more help in their forum – Asenar Oct 30 '13 at 10:40
  • I'm looking on this way –  Oct 30 '13 at 11:24

1 Answers1

0

You should insert the full path of the file you want to include. You can use __DIR__ (or dirname(__FILE__) to get the current directory, then, your code should look like this:

<?php
// add this to see an error if file is not found
// and don't forget to remove this in production mode
error_reporting(E_ALL);ini_set('display_errors', 'On');

$path = dirname(__FILE__).'/';
include_once ($path.'modules/developer/configure/classes/class.php');

Usually, the first called file define a constant like define('ROOT_DIR', __DIR__.'/') and use it for every inclusion or require.

EDIT : if __FILE__ and __DIR__ are not available because of server configuration, you can looks at Get absolute path of current script ( and specially that answer ) for alternatives

Community
  • 1
  • 1
Asenar
  • 6,732
  • 3
  • 36
  • 49
  • Thank you for the error_reporting trick, I didn't know that and it shows many (minor) errors I have to correct. But it does not solve my initial issue, as dolphin don't let met write neither __FILE__ nor __DIR__ in my code (inside the block). It automatically erases both terms... –  Oct 30 '13 at 10:31
  • So try the link I added in my answer for alternatives, or check the dophin documentation about how to include file. – Asenar Oct 30 '13 at 10:38