Include class library

Hi all

i’m trying to use a 3rd party library with classes
Normally i’ve to create a test.php file with the following code

[INDENT]<?php
echo ‘start process<br>’;
require_once (’/var/www/spcdev/SpcEngine.php’);
echo ‘loading array<br>’;
$user = array(‘username’ => ‘usertest’, ‘email’ => ‘usertest@your-host.com’);
echo ‘create user<br>’;
Spc::createUser($user);
echo ‘end<br>’;
?>
[/INDENT]

and in this way everything is running well thru the command php -f test.php.

But if i use the same code inside a blank application on the onExecute event, then nothing seems to run: just the first message is showed and that’s all. No errors and no warning.

Someome have an idea?

Thank in advance.

I hope the path is correct and is allowed from the webserver process, and thatit has the proper rights… Anyway why dont you put a try catch except around it then you can find out what happens yourself.

Thank you fo the suggestion but seems the problem is on the “include” statement.

[INDENT]echo “start<br>”;
$file_include = ‘/var/www/spcdev/SpcEngine.php’;
echo “test “.$file_include.”<br>”;
if(file_exists( $file_include )){
echo “test ok “.$file_include.”<br>”;
include( $file_include );
echo “included <br>”;
$user = array(‘username’ => ‘user3’, ‘email’ => ‘user2@your-host.com’);
echo “array loaded <br>”;

Spc::createUser($user);
echo "done &lt;br&gt;";

}
else {
echo"Function file does not exist";
}[/INDENT]

And the program end at include statement. This is the ouput

[INDENT]start
test /var/www/spcdev/SpcEngine.php
test ok /var/www/spcdev/SpcEngine.php[/INDENT]

No idea…

odd I thought include would produce and warning and continue the script… Hang a try catch around it to see the error… That should help you further.

Hi. I have been able to put the code from an external php file into one of the SC libraries, then in my blank app’s onExecute event use include and it all works. I would try that appoach.

  1. go to Tools - Libraries - set to project - then upload the php file

  2. in your app, go to programming - libraries - check the box next to your new file

  3. in the blank app onExecute event:

require_once ‘Blablah.php’;
$myBlah = new Blah_Blah;

Note that the path is just the file as named in the Library. SC handles where that is actually stored I guess. The above definitely works for me - hope it helps :slight_smile:
Peace,
Jamie

Many tanks to all!!!

The tip about including in libraries make all easy and running now!

Another problem i’ve found is: if the include file don’t have the final “?>” then everything goes wrong !!! :rolleyes: that’s also my case and no warnings at all

Have a nice day!!