PHP Fatal error: Using $this when not in object context for script - class

I've got problem:
I have a script that I'm working with and just upgraded to PHP 5.3.
In my kit_parser.php I'm getting the following fatal error:
Fatal error: Using $this when not in object context in /home/sitename/public_html/secure/includes/hooks/kits/kit_parser.php on line 71
This is the section of code it's referencing:
LINE 71---> $this->kit__log_add(array("<b>PHP Warning</b> [$errno] $errstr on line $errline in file $errfile"));
function kit_error($errno, $errstr, $errfile, $errline, $die = false) {
if (1==1){//$this->displayErrors ) {
switch ($errno) {
/* Custom Errors */
case E_USER_ERROR:
break;
case E_USER_WARNING:
break;
case E_USER_NOTICE:
break;
case E_ERROR:
$this->kit__log_add(array("<b>PHP Error</b> [$errno] $errstr on line $errline in file $errfile"));
die();
break;
case E_WARNING:
$this->kit__log_add(array("<b>PHP Warning</b> [$errno] $errstr on line $errline in file $errfile"));
break;
}
return true;
}
return false;
}
Why is the error coming? Nothing found, never seen before in my other scripts. Can anyone help me please?

This error usually means that you're using $this in a static class method. Make sure that the method this code is in is not static. If it is, you should probably be using this syntax instead:
YourClassNameGoesHere::kit__log_add(array("<b>PHP Warning</b> [$errno] $errstr on line $errline in file $errfile"));

Related

Use of undefined constant APPATH - assumed 'APPATH'

I encounter this Error and i can't Fix it, Someone please help me T_T
A PHP Error was encountered
Severity: Notice
Message: Use of undefined constant APPATH - assumed 'APPATH'
Filename: controllers/Pages.php
Line Number: 4
Backtrace:
File: C:\xampp\htdocs\Project\application\controllers\Pages.php
Line: 4
Function: _error_handler
File: C:\xampp\htdocs\Project\index.php
Line: 315
Function: require_once
and this is my Code
<?php
class Pages extends CI_Controller{
public function view($page = 'home'){
if(!file_exists(APPATH.'views/pages'.$page.'php')){
show_404();
}
$data['title'] = ucfirst($page);
$this->load->view('tenplates/Header');
$this->load->view('pages/'.$page, $data);
$this->load->view('tenplates/Footer');
}
}
When you get a message like...
A PHP Error was encountered
Severity: Notice
Message: Use of undefined constant APPATH - assumed 'APPATH'
Filename: controllers/Pages.php
....
It means the constant, in this case APPATH is not defined. So could be a typo?
If you check out the user guide it states that it is actually APPPATH. A good way to remember it is imagining it as APPlication PATH.
3 "P"'s - not two.
So your code would then become...
<?php
class Pages extends CI_Controller{
public function view($page = 'home'){
if(!file_exists(APPPATH.'views/pages'.$page.'php')){
show_404();
}
$data['title'] = ucfirst($page);
$this->load->view('tenplates/Header');
$this->load->view('pages/'.$page, $data);
$this->load->view('tenplates/Footer');
}
}

Errors in codeigniter-restserver library

I want to use restful in my ci 3.03 application:
I found this tutplus tutorial
I downloaded codeigniter-restserver-master.zip file and copied Format.php and REST_Controller.php(#version 3.0.0) files into /application/libraries/REST directory
I created control application/controllers/api/Users.php :
require_once("application/libraries/REST/REST_Controller.php");
require_once("application/libraries/REST/Format.php");
class Users extends REST_Controller
{
//protected $rest_format = 'json';
function users_get()
{
//$users = $this->user_model->get_all();
$filter_username= $this->get('filter_username');
$filter_user_group= $this->get('filter_user_group');
$filter_active= $this->get('filter_active');
$sort= $this->get('sort');
$sort_direction= $this->get('sort_direction');
//, $filter_user_group, $filter_active, $sort, $sort_direction
$users_list = $this->muser->getUsersList(false, ''/*, $filter_username, $filter_user_group, $filter_active, $sort, $sort_direction, ''*/);
echo '<pre>'.count($users_list).'::$users_lists::'.print_r($users_list,true).'</pre>';
if($users_list)
{
$this->response($users, 200);
}
else
{
$this->response(NULL, 404);
}
}
AND RUNNING URL http://local-ci3.com/api/users I got many errors:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Users::$format
Filename: REST/REST_Controller.php
Line Number: 734
Backtrace:
File: /mnt/diskD_Work/wwwroot/ci3/application/libraries/REST/REST_Controller.php
Line: 734
Function: _error_handler
File: /mnt/diskD_Work/wwwroot/ci3/application/libraries/REST/REST_Controller.php
Line: 649
Function: response
File: /mnt/diskD_Work/wwwroot/ci3/index.php
Line: 292
Function: require_once
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Users::$format
Filename: REST/REST_Controller.php
Line Number: 752
Backtrace:
File: /mnt/diskD_Work/wwwroot/ci3/application/libraries/REST/REST_Controller.php
Line: 752
Function: _error_handler
File: /mnt/diskD_Work/wwwroot/ci3/application/libraries/REST/REST_Controller.php
Line: 649
Function: response
File: /mnt/diskD_Work/wwwroot/ci3/index.php
Line: 292
Function: require_once
Actually I wanted to get some workable library to help me with REST api creation. I think that is preferable way istead of making from zero.
But is this library not workable or does it needs for some fixing? Sorry, what I missed is if this library only for ci 2?
I made search on this forum and found such hint :
I have the same problem when I load both Format.php and
Rest_Controller.php into a controller. After have a quick glance at
Format.php, it appears to be a standalone format conversion helper.
Try to just load Rest_Controller.php and see if your problem goes
away.
I commented line
//require_once("application/libraries/REST/Format.php");
in my controller, but I still get errors like :
Message: Undefined property: Users::$format.
I tried to review code of this library and see that invalid block when data are converted to json format, line 731-757 :
elseif ($data !== NULL)
{
// If the format method exists, call and return the output in that format
if (method_exists($this->format, 'to_' . $this->response->format))
{
// Set the format header
$this->output->set_content_type($this->_supported_formats[$this->response->format], strtolower($this->config->item('charset')));
$output = $this->format->factory($data)->{'to_' . $this->response->format}();
// An array must be parsed as a string, so as not to cause an array to string error
// Json is the most appropriate form for such a datatype
if ($this->response->format === 'array')
{
$output = $this->format->factory($output)->{'to_json'}();
}
}
else
{
// If an array or object, then parse as a json, so as to be a 'string'
if (is_array($data) || is_object($data))
{
$data = $this->format->factory($data)->{'to_json'}();
}
// Format is not supported, so output the raw data as a string
$output = $data;
}
}
If I tried to commented this block, but get error
Message: Array to string conversion
Looks like data are not converted in this case...
Is is possible to fix these errors?
Or can you, please, to tell me advice some codeigniter 3 REST api workable library with similar interface like library above?
Thanks!
I use that lib, work just fine. My suggestion is follow the more relevant installation instruction on github .
you also wrong place the lib file :
Tutorial say :
require(APPPATH'.libraries/REST_Controller.php');
You try :
require_once("application/libraries/REST/REST_Controller.php");
require_once("application/libraries/REST/Format.php");
No need to include the format because on line 407 the lib will load it. And also good to know on line 404 it will load the configuration (application/config/rest.php) it will be your default configuration, and also you can change it to suit your need.
Please let me know if you still got error using my answer :)

Fatal error: Class 'Mage_Productview_Helper_Data' not found in /app/Mage.php on line 546

In Magento admin, when trying to Add a New Role I am getting this error:
Login to admin
Go to System->Permmissions->Roles->Add New Role
Fatal error: Class 'Mage_Productview_Helper_Data' not found in /app/Mage.php on line 546
Please help. I tried to replace Adminhtml folder with fresh extraction folder but could not help
I solved this by:
adding
public static function helper($name)
{
$registryKey = '_helper/' . $name;
if (!self::registry($registryKey)) {
$helperClass = self::getConfig()->getHelperClassName($name);
if ($helperClass != "Mage_Productview_Helper_Data" )//add THIS line
self::register($registryKey, new $helperClass);
}
return self::registry($registryKey);
}
to /app/Mage.php (line 547)
And also, comment out:
if ( is_null($represent2Darray) ) {
//$result[$resourceName]['name'] = Mage::helper($module)->__((string)$resource->title);
$result[$resourceName]['level'] = $level;
}
in /app/code/core/Mage/Admin/Model/Roles.php (line 160)
Hope this helps.

send email through cakephp shell Fatal error: Class 'CakeLog' not found

i am trying to send email using cakephp shell. Following is my code:
<?php
error_reporting(0);
class EmailShell extends AppShell {
public $uses = array('Email');
public function show() {
$Email = new CakeEmail();
$Email->from('abc#gmail.com');
$Email->to('xyz#gmail.com');
$Email->subject('Forgot Password');
$Email->send();
}
}
?>
when i run this in shell i get the following error:
Fatal error: Class 'CakeLog' not found in /mnt/public_html/music_directory/web/cakephp/app/Config/bootstrap.php on line 172
where am i getting wrong? how do i solve it?
If you actually use the CakeLog class that early (in your own bootstrap)
you need to assert it is loaded.
You forgot the following statement prior to using the class:
App::uses('CakeLog', 'Log');

SoapClient error fallback in PHP

In PHP, if you try to instantiate a new SoapClient, and the WSDL is not accessible (server down or whatever), a PHP fatal error is thrown:
Fatal error: SOAP-ERROR: Parsing WSDL:
Couldn't load from
'http://example.com/servlet/app/SomeService?wsdl'
: failed to load external entity
"http://example.com/servlet/app/SomeService?wsdl"
Fatal errors in PHP, as far as I know, are not recoverable.
Is there any way to fallback from this? Can this fatal error somehow be avoided?
Edit: I should say that I am running on PHP 5.2, if it makes any difference.
This has already been discussed :
https://bugs.php.net/bug.php?id=47584
http://www.php.net/manual/en/class.soapclient.php#104046
Rasmus himself proposed the following solution:
<?php
try {
$x = #new SoapClient("non-existent.wsdl",array("exceptions" => 1));
} catch (SoapFault $E) {
echo $E->faultstring;
}
echo "ok\n";
See this topic How do I catch a PHP Fatal Error
Basically you cant recover from a fatal error but you can provide a better experience to the user when registering a shutdown function
register_shutdown_function('handleShutdown');
function handleShutdown(){
$error = error_get_last();
if($error !== NULL){
echo "Sorry for the inconvenience, an error just occurred.";
}
}