I have this code in a file named server.class.php:
class server
{
function addPlayer($player)
{
//Stuff
}
}
Then, I have this in a file called send.php. These are lines 38-40:
require('/var/www/server/apply/server.class.php');
$server = new server;
$server->addPlayer($_POST['IGN']);
However, I get this error when I visit my page (Php.ini is set to show all errors):
Fatal error: Class 'server' not found in /var/www/server/apply/send.php on line 39
Line 39 is $server = new server;
What am I doing wrong? I have verified that the class file is in /var/www/server/apply/server.class.php.
$server = new server()
Missed the brackets
Related
I am using a third party class that works well as long as I use it in the main body of my PHP script. If I try to use it in a function that is called from main, it gets a "PHP Fatal error: Class 'RouterOS\Util' not found error". What do I need to do in the function so it can use the class?
<?php
require_once '/usr/local/sbrc/MTAPI/vendor/autoload.php';
...
GetNextRouter($loginData[0]['User'], $loginData[0]['Password'], $firstAddress[0]['IPAddress']);
...
}
function GetNextRouter($UserID, $Pass, $Address) {
$util = new RouterOS\Util($client = new RouterOS\Client($Address, $UserID, $Pass));
...
}
The error occurs on the $util = new RouterOS\Util line.
Adding
use PEAR2\Net\RouterOS;
solved my issue
I am transfering my customer and product information to a new install of magento and when importing with CSV im hit with this:
Fatal error: Class 'Mage_Core_Helper_File_Storage' not found in /home/wwwsmkd/public_html/wholesale/app/Mage.php on line 547
This is the code
public static function helper($name)
{
$registryKey = '_helper/' . $name;
if (!self::registry($registryKey)) {
$helperClass = self::getConfig()->getHelperClassName($name);
self::register($registryKey, new $helperClass); // Line 547
}
return self::registry($registryKey);
}
Please check this path
app\code\core\Mage\Core\Helper\File\Storage.php
Does Storage.php file exist or not?
If this file not exist then may be the issue with new magento installation.
Hope this helps you some how.
i am following a tutorial to create an OOP based login system.I did everything accordingly but while creating pdo i am getting an error in DB.php file in line 15.Can't figure out the reason for this error.Been stuck there for some time.Can anyone help me out with this error .The code might look long but it is a piece of cake for you i promise.There are FOUR php files.
1.init.php file holds the ingredients to create a new PDO() object.
2.config.php file is used to get data from init.php file as string is passed to it as ('mysql/host') type and use explode() function to extract data from it.
2.DB.php file is used to connect to database.
The error i am getting is
DB.php file:
class DB{
private $_instance=null;
private $pdo,
$query,
$error=false,
$results,
$count=0;
private function __construct(){
try{
$this->$pdo=new PDO('mysql:host='.Config::get('mysql/host').';dbname='.Config::get('mysql/db'),Config::get('mysql/user'),Config::get('mysql/password'));
}catch(PDOException as $e){
echo $e->getMessage();
}
}
public static function getInstance(){
if(!isset(self::$_instance)){
self::$_instance=new DB();
}
return self::$_instance;
}
}
Config.php file:
class Config{
public static function get($path){
if($path){
$config=$GLOBALS['config'];
$arr=explode('/',$path);
foreach($arr as $bit){
if(isset($config[$bit])){
$config=$config[$bit];
}
}
return $config;
}
}
}
init.php file:
session_start();
$GLOBALS['config']=array(
'mysql'=>array(
'host' => 'localhost',
'db' => 'login',
'user' => 'root',
'password' => ''
)
);
spl_autoload_register(function($class){
require_once 'c:/xampp/htdocs/login/classes/'.$class.'.php';
});
require_once 'c:/xampp/htdocs/login/function/sanitize.php';
index.php file:
require_once 'c:/xampp/htdocs/login/core/init.php';
DB::getInstance()->query('SELECT name FROM table WHERE id=1');
Your error message is a Parse Error. This means the PHP interpreter/processor/program tried to read your file, but found a syntax error, and had to stop. If you look at Line 15 of DB.php (per the error message)
}catch(PDOException as $e){
You'll see the problem. This isn't valid PHP syntax -- you probably want
}catch(PDOException $e){
The PDOException bit of that is a a class type hint for the exception handling code -- there's no need to use the as.
Hi i am trying to import the configuration variables from a config file that i had created
Config.php has
class Config
{
public $SERVERNAME = '*******';
public $SUSERNAME = '*********';
public $SPASSWORD = '*********';
public $DBNAME2 = '********';
}
for importing this variable in another file i tried
include('./Config.php') or die("error");
$cnfig = new Config();
But when i try to use $cnfig->DBNAME2 its not working
Please help to sole this problem.
Thank you.
EDIT
It was working in localsystem , when i tied to upload through web hosting it was not working.
Try below one
include ('./Config.php');
$cnfig = new Config();
echo "<pre>";print_r($cnfig);
Edit:
I am getting below output so it should be working for you too.
Config Object
(
[SERVERNAME] => *******
[SUSERNAME] => *********
[SPASSWORD] => *********
[DBNAME2] => ********
)
Edit:2
You can also do like this
(include('./Config.php')) or die("error");
$cnfig = new Config();
echo "<pre>";print_r($cnfig);
http://www.php.net/manual/en/function.include.php#39043
or has higher priority than include()
Error Ouput:
When only use include('./Config.php') or die("error"); it's giving below error.
Warning: include(1) [function.include]: failed to open stream: No such file or directory in D:\path_to_file\myConfig.php on line 2
Warning: include() [function.include]: Failed opening '1' for inclusion (include_path='.;D:\ZendServer\share\ZendFramework\library') in D:\path_to_file\myConfig.php on line 2
Fatal error: Class 'Config' not found in D:\path_to_file\myConfig.php on line 6
I have a wsdl file and i am trying to call it from a php class. I am using the following code:
<?php
include ("dbconn.php");
class dataclass
{
function getCountries()
{
$connection = new dbconn();
$sql = "SELECT * FROM tblcountries";
$dataset = $connection -> connectSql($sql);
return $dataset;
}
function getTest()
{
$connection = new dbconn();
$sql = mysql_query('CALL sp_getTest');
$dataset = $connection -> connectSql($sql);
return $dataset;
}
##-------------------------------------------CUSTOMER METHODS-------------------------------------------
function registerCustomer($username,$name,$surname,$password,$email,$country,$tel)
{
$connection = new dbconn();
$sql="INSERT INTO tblcustomer (customer_username, customer_password, customer_name, customer_surname,
customer_email, customer_country, customer_tel)
VALUES('$username','$name','$surname','$password','$email','$country','$tel')";
$dataset = $connection -> connectSql($sql);
}
ini_set("soap.wsdl_cache_enabled", "0");
// start the SOAP server - point to the wsdl file
$webservice = new SoapServer("http://localhost/dataobjects/myWebservice.wsdl", array('soap_version' => SOAP_1_2));
// publish methods
$webservice->addFunction("getCountries");
$webservice->addFunction("registerCustomer");
// publish
$webservice->handle();
}
?>
It is all the time giving me a problem with ini_set("soap.wsdl_cache_enabled", "0");
The error is:
Parse error: syntax error, unexpected T_STRING, expecting T_FUNCTION in C:\Program Files\xampplite\htdocs\dataobjects\dataClass.php on line 47
I believe it is because you have ini_set() call in the body of your class. Put it at the top of the file or in the constructor if you have one.
class dataClass
{
function registerCustomer()
{
// some stuff
}
ini_set(/*args*/); // it's illegal to put instructions in the body of the class
}
Now I see the whole thing. You probably want to close the class with a closing backet before line 47.
You let the parser think "0" is a string, and not a number, please remove the quotes!
Edit 1 If that wouldn't work, your error must be before that line, please post the full code for review.
Edit 2 The code you provided was running inside the class, you miss a bracket before the line with ini_set.
Move the last } in front of ini_set(...)
By the way, you said you want to call a web service, but you are creating a server which may be called by others.
To call a web service, try something like this:
try{
$client = new SoapClient($service, array('location' =>"http://example.org/myWebService"));
$parameter1 = new myWebServiceParameter();
$result = $client->myWebServiceFunction($parameter1);
} catch (Exception $e) {
// handle errors
}
myWebServiceParameter must be any class with a member variable foreach WSDL message attribute of the same name.
And myWebServiceFunction is the name of the web service method.