PHP "Helper Class" - Class not found - php

I am having an issue that coming from PHP 5.3.2 to 5.3.3 the code no longer can find the "I2A2" class.
Here is some info:
Error:
ErrorException [ Error ]: Class 'I2A2' not found
Fatal error: Class 'I2A2' not found in /var/www/html/root/sandbox/lpolicin/t6/fuel/app/classes/observer/selectcustomer.php on line 6
$directory_listing = \I2A2::get_customer_info("puid",$customer->puid);
Code:
"classes/observer/selectcustomer.php "
class Observer_Selectcustomer extends Orm\Observer
{
public function after_load(Model_Customer $customer)
{
$directory_listing = \I2A2::get_customer_info("puid",$customer->puid);
}
}
"classes/I2A2.php"
class I2A2
{
if (static::$initalized === true)
{
return;
}
}
Auto loader (this is insert into a huge array then auto loads everyting)....
{
'always_load' => array(
'classes' => array(),
}
If you need more info please let me know!

Check your paths: the first is correctly fully lowercase but the second suddenly has the filename uppercase. All paths in Fuel are fully lowercase, no matter the classname. Thus change the filename for the I2A2 class to i2a2.php and it'll work.

Related

How to make an override for a function in a php file

I am using a module which is often updated by the developing company.
In one php file (cat_product_get.php) of this module is the here below function :
function getColSettingsAsXML()
Inside this function is the following code :
{
foreach($colSettings[$col]['options'] AS $k => $v)
{
$xml.='<option value="'.str_replace('"','\'',$k).'"><![CDATA['.$v.']]></option>';
}
}
Such code leads to the following warning :
PHP Warning: Invalid argument supplied for foreach() in ../cat_product_get.php on line 317
Line 317 is the following :
foreach($colSettings[$col]['options'] AS $k => $v)
To fix the warning, I added one line as follows :
if (is_array($colSettings[$col]['options']) || is_object($colSettings[$col]['options']))
{
foreach($colSettings[$col]['options'] AS $k => $v)
{
$xml.='<option value="'.str_replace('"','\'',$k).'"><![CDATA['.$v.']]></option>';
}
}
But at each module update, I have to amend again the cat_product_get.php.
I tried to convince many times the developer to add the suited line in his code.
But the developer refused to do it.
Is there a way to add somewhere an override to avoid the line addition at each module update ?
I am not a developer...
I thank you in advance for any reply.
Patrick
If the function is just a plain function, then it can't be done in PHP. You can't have duplicate function names.
If it is a function in a class (aka a method), you can extend that class and just rewrite the function, and use your class.
class Person
{
public function fixThisCrap()
{
return 'the wrong stuff';
}
// more functions
}
class MyPerson extends Person
{
public function fixThisCrap()
{
return 'the correct stuff';
}
// parent class functions will be available, no need to code
}

Fatal error: Call to undefined method objectInfo::objectInfo()

I don't find exactly where is my problem. It seems the objectinfo is empty and
I have this error on.
Fatal error: Call to undefined method objectInfo::objectInfo() on this line $bInfo->objectInfo($banner);
My sql request work fine and I verified
There my code where is the problem.
Tk
$parameters = array('expires_date' => '',
'date_scheduled' => '',
'banners_title' => '',
'banners_url' => '',
'banners_group' => '',
'banners_target' => '',
'banners_image' => '',
'banners_html_text' => '',
'expires_impressions' => '',
'banners_title_admin' => ''
);
$bInfo = new objectInfo($parameters);
$bID = HTML::sanitize($_GET['bID']);
$Qbanner = $OSCOM_PDO->prepare('select banners_title,
banners_url,
banners_image,
banners_group,
banners_target,
banners_html_text,
status,
date_format(date_scheduled, "%Y-%m-%d") as date_scheduled,
date_format(expires_date, "%d/%m/%Y") as expires_date,
expires_impressions,
date_status_change ,
customers_group_id,
languages_id,
banners_title_admin
from :table_banners
where banners_id = :banners_id
');
$Qbanner->bindInt(':banners_id', (int)$bID);
$Qbanner->execute();
$banner = $Qbanner->fetch();
$bInfo->objectInfo($banner); // pb is here
As par i know this Fatal error occur due to the updated version of the php.
Earlier, we are able to autoload the class property by using the same function name of the class name.
In Earlier varsion of PHP, we can able to call or define the Same Function name of the class name.
But new the Latest version of php we can not do that. if we use the same function name of the class name and if we call this function name then it give us the fatal error like you received in this post.
So the solution is as follow.
Go to the class objectInfo ( or whatever you have )
your class file is currently have
class objectInfo {
function objectInfo($object_array) {
your function code here.....
}
}
Change the function name from objectInfo to __construct. so the entire class is looking like as below
class objectInfo {
function __construct($object_array) {
your function code here.....
}
}
currently you call the function like
$bInfo = new objectInfo($parameters);
$bInfo->objectInfo($banner);
so change above code as below.
$bInfo = new objectInfo($parameters);
$bInfo->__construct($banner);
so finally hope that your error will be solved.
The line $bInfo = new objectInfo($parameters); created a new instance of the objectInfo class. Then you attempt to call the method objectInfo() of this class. The error message just tells you that this class has no such method. Can you show the source code for the class objectInfo?

Autoload Obscurity

I"m sorry now but I don't know if I can get all the details possible to make an educated guess on what exactly is going on.
I'm trying to check to see if a class exists, if it doesn't I need to create the class. Some classes have sub classes (namespaces).
namespace {
class wattsjus {
}
}
namespace wattsjus {
class OtherClass {
}
}
so whether I __autoload wattsjus or wattsjus\OtherClass I'm loading both classes.
I can tell that up until the point I load the classes they are not there if I try and autoload the 'inner class'. After I load the class I get an error that the class is already loaded. Yet I can print text just before that point and that line is never reached.
I am using class_exists to make sure the wattsjus class is not loaded. Before I load the class this is true (loaded). yet if I try to make an instance of wattsjus it cannot be found.
I'm using the following code to check where the class was created and it's stating a line number that is never reached at this point. I have an print statement before this line to be sure.
$reflector = new ReflectionClass('wattsjus');
echo $reflector->getFileName();
A great mystery to me as to how code could have been reached without executing the previous line.
Edit, Warning this is ugly code:
function __autoload($class_name) {
echo 'in';
$parts = explode('\\',$class_name);
if($class_name == $_GET['u5u'] || $parts[0] == $_GET['u5u']) {
$cl = class_exists($_GET['u5u'], false);
echo $cl ? 'yes' : 'no';
if(!$cl) {
if($_GET['e5e'] != 'Prod') { $env = $_GET['e5e']; }
$q = "SELECT f.`Name`, f.`$env"."ParameterList` `ParameterList` FROM `Function` f WHERE f.UserId = ".SiteUserId." AND `Status` = 'A' ORDER BY INSTR(f.`Name`, '\\\\') > 0, f.`Name`";
$results = DataObject::GetDBObject()->Query($q, 'wattsjus_json');
$class = "namespace { class $_GET[u5u] {";
$class .= GetFunctions($results);
$class .= '}}';
echo 'I\'m not here yet';
eval($class);
} else {
$reflector = new ReflectionClass('wattsjus');
echo $reflector->getFileName();
}
here the output that is produced trying to get OtherClass is:
inyes/home4/wattsjus/public_html/ajson/global_base.php(25) : eval()'d code<br />
<b>Fatal error</b>: Class 'wattsjus\OtherClass' not found in <b>/home4/wattsjus/public_html/ajson/global_base.php(112) : runtime-created function</b> on line <b>1</b><br />
so to me this is saying that the class wattsjus already exists which should include OtherClass in the namespace. Though it cannot be found. If I let it keep going and create wattsjus again it will say the class has already been defined. Very confusing I know.
I changed the structure of the classes to use "namespace wattsjus\OtherClass" rather than make a OtherClass class and for some reason PHP is less confused by this. Really weird glitch/bug I'd have to say.
namespace {
class wattsjus {
}
}
namespace wattsjus\OtherClass {
}

Cannot load custom content type nodes with load_node_multiple or load_node

I have a custom content type called "program" that I am trying to load via a drupal module.
The .module file includes a class called Program that has a method called
getAllPrograms() using include_once(drupal_get_path('module', 'progs') . '/progs.php');
When i try and load nodes using either node_load() or node_load_multiple() i get one of two different errors randomly.
either:
Fatal error: Fatal error: Call to undefined function user_access() in /mypath/modules/filter/filter.module on line 1035
or
Error: Call to undefined function token_get_entity_mapping() in /mypath//sites/all/modules/contrib/token/token.tokens.inc, line 767
Note: 99% of times it is the first error, and occasionally i would recieve the token_get_entity error.
The strange thing is, while i have been trying different things to resolve the error I have been able to get both of these functions to work for a period but as soon as i clear the Drupal Cache i get the error again.
What I have tried
Disabling and enabling the user module via the database.
Checking the paths and status are correct for the main modules (system, user, block etc)
using db_select to get a list of node ids and then use node_load() (with a loop) and node_load_multiple() to load the nodes. This is one of the things that started working for a short time until i cleared the cache.
Tested to see if i can call user_access() from my .module file. This does not work and returns the same call to undefined function error.
Here is the code that I have (not progs an anonymized name)
progs.module
include_once(drupal_get_path('module', 'progs') . '/progs.php');
progs.php
if( !class_exists('progs') ):
class progs
{
//a bunch of properties
function __construct()
{
// load partial includes and objects
$this->load_partial_inclues();
//retrieve all programs that are open
$this->open_programs = Program::getAllOpenPrograms();
}
function load_partial_inclues()
{
//includes
include_once(drupal_get_path('module', 'progs') . '/core/objects/program.php');
}
}
function progs()
{
global $progs;
if( !isset($progs) )
{
$progs = new progs();
}
return $progs;
}
// initialize
progs();
endif;
Note: I load the $progs into the global space so i can call it elsewhere in my module.
program.php
if( !class_exists('Program') ):
class Program
{
//a bunch of properties
public static function getAllOpenPrograms()
{
// This is the line that causes all of the issues.
$result = node_load_multiple('',array('type' => 'program'));
dpm($result);
}
Thanks in advance!
Like Mike Vranckx mentioned, if you call progs() directly when you include it in progs.module, Drupal basically hasn't bootstrapped, i.e. hasn't started running fully yet. Suggest you put your progs() in progs_init() or similar so that Drupal will invoke it at the right time.
Here's a proposed way that follows your initial structure quite closely, and below you will see an alternative that better follows Drupal's conventions.
New progs.module
/**
* Implements hook_init().
*/
function progs_init(){
progs();
}
And modify your progs.php
// Why are you doing this check? Are you defining this class elsewhere in your project? If not you can safely ignore this
//if( !class_exists('progs') ):
// Convention is to name classes with Pascal case btw.
class progs
{
//a bunch of properties
function __construct()
{
// load partial includes and objects
$this->load_partial_inclues();
//retrieve all programs that are open
$this->open_programs = Program::getAllOpenPrograms();
}
function load_partial_inclues()
{
//includes
include_once(drupal_get_path('module', 'progs') . '/core/objects/program.php');
}
}
function progs()
{
global $progs;
if( !isset($progs) )
{
$progs = new progs();
}
return $progs;
}
A more Drupal way:
progs.module
/**
* Implements hook_init().
*/
function progs_init(){
global $progs;
// Consider using drupal_static to cache this
if( !isset($progs) )
{
module_load_include('inc', 'progs', 'progs');
$progs = new Progs();
}
}
progs.inc (convention is to use .inc)
class Progs
{
//a bunch of properties
function __construct()
{
// load partial includes and objects
$this->load_partial_inclues();
//retrieve all programs that are open
$this->open_programs = Program::getAllOpenPrograms();
}
function load_partial_inclues()
{
//includes
module_load_include('php', 'progs', 'core/objects/program');
}
}

Fatal error: Class 'Zend_Log' not found

I'm getting the following error in magento administration
Fatal error: Class 'Zend_Log' not found in /home/website/public_html/app/code/community/Uni/Fileuploader/Block/Adminhtml/Fileuploader/Edit/Tab/Products.php on line 241
This is a community extension, which has been working fine on my website. The error makes no sense to me, because the line 241 contains just a closing "}" character.
class Uni_Fileuploader_Block_Adminhtml_Fileuploader_Edit_Tab_Products extends Mage_Adminhtml_Block_Widget_Grid {
...
...
...
public function getRowUrl() {
return '#';
}
public function getGridUrl() {
return $this->getUrl('*/*/productgrid', array('_current' => true));
}
protected function getFileuploaderData() {
return Mage::registry('fileuploader_data');
}
protected function _getSelectedProducts() {
$products = $this->getRequest()->getPost('selected_products');
if (is_null($products)) {
$products = explode(',', $this->getFileuploaderData()->getProductIds());
return (sizeof($products) > 0 ? $products : 0);
}
return $products;
}
} // line 241, where error occurs
I can post the rest of the code, if you need it.
I noticed that if I upgrade to PHP 5.4 version the error disappears, but since 5.4 version causes other errors on my website, I have to continue using 5.3.
Any ideas on how to solve this?
The problem could be the name of one of the methods in your custom class.
Take for example the method name is getData() ,
Try searching for generic method names in your script, such as getData, which might be reserved by some of Magento’s core classes. I figure that these methods have predefined functionality, which your module is missing support for, and Zend then tries to write an exception to Zend log.
Reference link: netismine
I got the same error when rewriting a payment method.
public function authorize($payment, $amount)
Solved rewriting exactly the same main method:
public function authorize(Varien_Object $payment, $amount)
Magento 1.9.1.0/PHP 5.5

Categories