I am using this API "https://github.com/infusionsoft/PHP-iSDK".
I am calling it in a simple php file but I am having a error, I am new to php any body with some easy solution, here is my code.
<?php
echo "Hello World! <br/>";
include_once('iSDK/src/isdk.php');
$myApp = new iSDK;
if($myApp->cfgCon("connectionName")) {
echo "Connected...";
} else {
echo "Not Connected...";
}
sendEmail('conList','fromAddress','toAddress', 'ccAddresses', 'bccAddresses', 'contentType', 'subject', 'htmlBody', 'txtBody');
?>
This code below give this error :
Call to undefined function sendEmail() in C:\xampp\htdocs\test\email.php on line 16
Is this the only error in this code?
It looks like php can't find the function within iSDK.
The line nclude_once'iSDK/src/isdk.php'; should be include_once('iSDK/src/isdk.php'); and you should check, if the relative path is correct.
The first character in the next line is also missing: myApp = new iSDK; should be $myApp = new iSDK();
Second guess is to write $myApp->sendEmail( instead of sendEmail(
Related
If you have two files, file-a.php and file-b.php
file-a.php contents:
require 'file-b.php';
my_test( 'hi' );
and file-b.php contents:
function my_test( $text ) {
echo $text;
}
Then "hi" is echo'd normally as expected.
But if in file-b.php you add a return on the first line, like this:
return;
function my_test( $text ) {
echo $text;
}
then nothing is echo'd, but there is also no error notice saying that "my_test" method was not declared anywhere.
Why is this happening? I expected an error of undeclared function.
Edit: To clarify. If I then make file-a.php contents:
require 'file-b.php';
my_test( 'hi' );
my_second_test_that_doesnt_exist( 'hi' );
Then I do get a 'Call to undefined function "my_second_test_that_doesnt_exist"'
You're returning from the file. So everything under the line "return" isn't executed. BUT it gets noticed by PHP, so even if you can't call it, PHP knows that it exists so it won't throw an error.
I have a project on PHP and I have to use a DOTNET DLL which was written on C# . I have to call different functions of the same object in two different PHP pages. In the first page it works but I get this error in the second page. Can you please help me? These are example ;
DOTNET DLL :
namespace FirstDotNet
{
[ComVisible(true)]
public class Class1
{
public string SampleFunction()
{
return "hello";
}
}
}
PHP Class File animals.php
class Animal{
var $abc;
public function do_it(){
$this->abc = new DOTNET("FirstDotNet, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxx", "FirstDotNet.Class1");
}
}
First PHP FILE a.php (this works, output is 'Hello')
require_once("animals.php");
session_start();
$first_animal = new Animal();
$_SESSION["animal"] = $first_animal;
$first_animal->do_it();
echo $first_animal->abc->SampleFunction();
Second PHP FILE b.php (this doesnt work, output is Fatal error: Call to undefined method dotnet::SampleFunction())
require_once("animals.php");
session_start();
$animal2 = $_SESSION["animal"];
echo $animal2->abc->SampleFunction();
$code = 'php statement';
// getting perse error
function perse_error_check($code){
if(eval($code) === "true"){
return "no perse error";
}
if(eval($code) === "false"){
return "perse error found";
}
}
// getting fatal error
function fatal_error_check($code){
.......................................
.......................................
}
Can you help me to complete the second function? Actually I am not sure weather it is possible or not.
The following writes the PHP code to another file.
It then uses command line execution to parse the file and check for erros:
/* Put the code to be tested in a separate file: */
$code = '<?php echo "Test"; ?>';
file_put_contents('check.php', $code);
/* Parse that file and store the message from the PHP parser */
$x = exec( 'php -l check.php');
/* Check the message returned from the PHP parser */
if(preg_match('/Errors parsing/i',$x))
{
echo 'The code has errors!';
}
else
{
echo 'The code looks good!';
}
/* delete the file */
unlink('check.php');
The benefit is that the code doesn't run, it just gets parsed. However I assume you would then write that code to a file and use it... so like others mentioned, be VERY careful. Use things like open_basedir (and test it) to restrict access to specific directories, manually check the code before including it in production... etc.
There is a simple way. Put your PHP code in an another file. For an example: index.php and check.php . Put your PHP code in check.php.
Now in index.php write:
$check_data = file_get_contents("yourhosturl/allotherdirectory/check.php");
if(preg_match("/Fatal error/",$check_data)){
echo "fatal error found";
}
I am using Facebook Ads API to pull data from ads Reporting.
Below is my code :
<?php
use FacebookAds\Object\AdAccount;
$account = new AdAccount('act_xxxx');
$params = array(
'date_preset'=>'last_28_days',
'data_columns'=>"['adgroup_id']",
);
$stats = $account->getReportsStats(null, $params);
foreach($stats as $stat) {
echo "is it inside the foreach loop \n";
echo $stat->impressions;
echo $stat->actions;
}
?>
I get FacebookAds/Object/AdAccount not found. I checked the path and everything looks correct. any idea, what could be the reason for this error. I am not a PHP Expert, so please do correct me, if something is wrong with my code.
<?php
function __autoload($class) {
require_once $class.".php";
}
Save this file as autoload.php in same directory then add below code at start
<?php
require_once('./autoload.php');
Explanation:
In your code you haven't included the file which contains the class FacebookAds\Object\AdAccount. That's why it gives class not found error.
Above code will make sure that all necessary class files are include in code.
I have a class similar to this
class x {
function __construct($file){
$this->readData = new splFileObject($file);
}
function a (){
//do something with $this->readData;
}
function b(){
//do something with $this->readData;
}
}
$o = new x('example.txt');
echo $o->a(); //this works
echo $o->b(); //this does not work.
it seems if which ever method called first only works, if they are called together only the first method that is called will work. I think the problem is tied to my lack of understand how the new object gets constructed.
The construct is loaded into the instance of the class. And you're instantiating it only once. And accessing twice. Are different actions. If you want to read the file is always taken, should create a method that reads this file, and within all other trigger this method.
I tested your code and it worked normal. I believe it should look at the logs and see if any error appears. If the file does not exist your code will stop.
Find for this error in your apache logs:
PHP Fatal error: Uncaught exception 'RuntimeException' with message 'SplFileObject::__construct(example.txt): failed to open stream
Answering your comment, this can be a way:
<?php
class x {
private $defaultFile = "example.txt";
private function readDefaultFile(){
$file = $this->defaultFile;
return new splFileObject($file);
}
function a (){
$content = $this->readDefaultFile();
return $content ;
}
function b(){
$content = $this->readDefaultFile();
return $content ;
}
}
$o = new x();
echo $o->a();
echo $o->b();
Both methods will return an object splFile.