PHP array error: Indirect modification of overloaded property - php

Why is this line of code:
$this->plugins_dir[0] = SMARTY_DIR . 'plugins';
causing this error?
ERRNO: 8
TEXT: Indirect modification of overloaded property Page::$plugins_dir has no effect
By the way, the line of code is inside the constructor of a class named 'Page'.
I am working with PHP and PostgreSQL, but am not too experienced. I am stuck
with this problem for few hours now, can't find the reason.

What PHP is trying to tell you is that the property ->plugins_dir doesn't really exist, but a magic __get() function has been written that will return a value if you read from it. Assigning a variable directly to it might also work (if there is a corresponding __set()) but you cannot modify it, since it is actually a function return value. You are effectively trying to say $this->__get('plugins_dir')[0] = 'foo', which doesn't mean anything.
However, looking at the relevant Smarty documentation, we can see what the correct solution is:
Note: As of Smarty 3.1 the attribute $plugins_dir is no longer accessible directly. Use getPluginsDir(), setPluginsDir() and addPluginsDir() instead.
So your code should actually use the pattern of one of the examples on the doc page for addPluginsDir(), such as:
$this->setPluginsDir( SMARTY_DIR . 'plugins' )
->addPluginsDir( '/some/other/source/of/plugins' );

I think this is the right way
$this->plugins_dir = SMARTY_DIR . 'plugins';

Related

Include PHP File and execute it multiple times

Yeah I know this is probably not the best way to perform this. However I have a script which I would like to call multiple times with parameters and hand over two variables. The code I have so far looks like this:
$testfeld = array('User1'=>'400028',
'User2'=>'400027'
);
foreach($testfeld as $key=>$value) {
$_GET['cmd'] = 'modify';
include("testmodify.php");
}
If I run this code, I get an error message:
Fatal error: Cannot redeclare show() (previously declared in testmodify.php:14) in testmodify.php on line 39
If I perform this, it only modifys me the first entry of the array and then throws me the error message above.
Sadly, I have only read access to testmodify.php.... So is there a way to perform this include with all the content of the array?
Put your code in the function, include it once and call as much as you want.
You are receiving this error because the file testmodify.php contains the definition for "show". A second inclusion of the file caused by your loop attempts to define the object show again, which cannot be done.
Here is another SO question about someone trying to redefine a function.
Php and redifining
Edit: the other answer by MilanG is how you could go about fixing it.
You can do something like (in your testmodify.php script):
if (!function_exists("show")) {
function show($parameters) {
/* do your stuff here */
}
}
A better thing to do, in this case, would be to perform include_once() in your testmodify.php script, making it point to a script file where you define your show() function. My approach should also work for you.
Hope that helps :)

ModX Evo: PHP error in document.parser.class.inc.php

So my Evo site stopped working the other day - just got a 500 error. I got my host to check the logs and found this:
[error] PHP Fatal error: Cannot redeclare insert_metka() (previously declared in
/home/mysite/public_html/manager/includes/document.parser.class.inc.php(790) : eval()'d code:2)
in /home/mysite/public_html/manager/includes/document.parser.class.inc.php(790) : eval()'d code on line 12
I have tired commenting out the offending line and removing the entire file to no avail. Does anyone know what this means and how to fix it?
EDIT: the code at line 790:
eval ($pluginCode);
Looks like a bad plugin has broken your site. Disable all your plugins and reinstate them one at a time until it breaks again, then you know which one is the culprit.
Once you've done that, post the plugin code here and we can help you debug it further. You shouldn't ever need to modify the MODX source code.
The problem is likely to be solved by wrapping the insert_metka() declaration like this:
if(!function_exists('insert_metka')) {
function insert_metka() {
// function code
}
}
http://wiki.modxcms.com/index.php/Creating_Snippets#Wrap_functions_inside_.21function_exists_conditional_if_the_resource_is_needed_to_run_more_than_once_on_a_page
That appears like a very simple problem. You are declaring insert_metka() two times. Remove it from one of the mentioned files. Once it is declared in saved file and apparently second time you are trying to declare it with the help of eval()
Cannot redeclare insert_metka() says that you are declaring a function twice (may be with your evals).
You should check on your included files.
To be sure to not include more than one time, you can use include_once or requiere_once instead of include and requiere
Accoring to document.parser.class.inc.php this line i guess you are using OOP.
So what you can do is create instantiation class for above class and then overwrite it.
There are other things too. you might declaring same function inside of same class.

function to convert string to integer -- call to undefined function

I am creating a function that converts a users initials (STRING) to their userid (INT)
problem is when I call the function I get a call to undefined func error because the below declared function is no where to be found in the Source!
// connect to database -- this works, I checked it
function convertRadInitToRadID($radInits){
$sqlGetRadID="SELECT id FROM sched_roster WHERE radInitials == '".$radInits."'";
$resultGetRadID=mysql_query($sqlGetRadID);
$radID=mysql_result($resultGetRadID,0);
return $radID;
}
...I then create and array ($radNotOnVacay_and_NonMRNotonVacayWeekBeforeAndAfter) of user initials, it works with no errors I tested it independently
$randKey=rand(0,(count($radNotOnVacay_and_NonMRNotonVacayWeekBeforeAndAfter)-1));
$randRad=$radNotOnVacay_and_NonMRNotonVacayWeekBeforeAndAfter[$randKey];
$randAssignedRadID=convertRadInitToRadID($randRad); // call to undefined function error here
when I view source the function definition code (where I define the function) is nowhere to be seen in the source. Very strange. I tried placing it around different areas of the script, same error. The function definition is declared appropriately and is wrapped in .
Very strange. The function just doesn't appear. Quotations, syntax, semi-colons, etc are all spot on.
No syntax errors. Advice?
I Strongly agree with Answer #1.
In addition a usual problems occur in php if you are defining function after calling it. i.e. your calling code is before function defination then it will not run and will give an error of undefined function.
You can create a class then define this function in that class and on the time of calling you can call that function with help of $this->function(args)
I think this will resolve your problem in mean while i am trying to run your code on my machine, lets see what happen
May be your function is a method of some class. So, if it is, you should use it in another way:
MyClass::convertRadInitToRadID($radInits) // if static method
or like this
$class = new MyClass();
$class ->convertRadInitToRadID($radInits)
Trying to make sense of your question... Are you trying to call the function using JavaScript? If so, remember that JavaScript is run on the browser, and PHP is run on the server (and this is why when you "view source" you don't see the function anywhere). To send data back from JavaScript to PHP you should use AJAX.
I found the answer: I was using Jquery UI tabs.... there must be a conflict with tabs. When I run the code without tabs there is no issue.
Thanks for the '==' fix.. appreciate it. my bad
thanks for reminding me about the 80 char varname code limit

Multiple NuSOAP clients causes "Undefined index: _transient" error

I'm working with 0.9.5 and I'm doing some phpunit tests.
When I execute my second test, that invokes again the webservice, I'm getting this error:
Undefined index: _transient
/var/www/dev_folder/nusoap/nusoap.php:227
/var/www/dev_folder/nusoap/nusoap.php:7293
when
$client = new nusoap_client($this->_config->URL_Path . $webserviceWSDL, true);
is executed by a second time.
I checked nusoap.php and seems something related with globals or something static or singleton... but I don't know what can I do to solve the problem...
$GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel'] = 9;
Need nusoap client to be unloaded or something like this? Why this global variable is failing?
Thank you.
I had the same problem. The comments seemed to indicate that the global variable was an attempt to emulate a static class variable, so I simply updated the code to actually use a static class variable in the nusoap_base class. That seemed to do the trick.
You can checkout the code here.

Fatal error with Custom Magento Module on one server but not the other

I am creating my own custom module in Magento and during testing on a Litespeed server (PHP v5.2.14) I am getting a Fatal Error: Call to a member function batch() on a non-object in ../../../BatchController.php on line 25 that was not appearing during testing on another linux server and a wamp server (PHP v5.2.11).
This one has stumped me. I am guessing it has something to do with the server configuration rather than the code itself. But i am just guessing. I was hoping someone here could tell me.
The only real major difference I could see, aside from the php versions and environment, is that the server that the error is on is using the Suhosin Patch. But would that be something that could cause this?
The line in question is Mage::getModel('mymodule/mymodel')->batch(); which is enclosed in an IF statement. batch() is a public function located in my model file.
If you need more code let me know.
Thanks!
If you get a "non-object" error when calling a model, there's a problem with Magento's attempt to get your model class, and it is returning null. The reasons for this are not always apparent. If this worked identically on a normal LAMP stack, then the problem is most likely not in your code.
My first guess would be that the file does not have the proper permissions. Otherwise, it may have to do with resolving the classname. You could test this temporarily by calling the plugin directly like this:
$obj = new Mynamespace_Mymodule_Model_Mymodel();
$obj->batch();
If this works, then the file is readable, and you will want to go spelunking in the resolution of that classname. If it doesn't work, you have a problem with either autoloading or the declaration of your class.
Hope that helps!
Thanks,
Joe
Break it down.
You've tried to call
Mage::getModel('mymodule/mymodel')->batch();
and PHP told you it tried to call the method batch on a non-object. That means
Mage::getModel('mymodule/mymodel')
isn't returning a Model object the way it's supposed to.
First thing to do is clear out your Magento cache on the server you're having problems with. If your Module's config hasn't been loaded into the global config tree Magento will try to instantiate a Mage_Core_Model_Mymodel, and fail.
Second step is to make sure your module's app/etc/module file is in place.
Third step is to add some debugging (assuming a 1.4 branch) to the method that instantiates your objects and determine why Magento can't create your object
File: app/code/core/Mage/Core/Model/Config.php
...
public function getModelInstance($modelClass='', $constructArguments=array())
{
$className = $this->getModelClassName($modelClass);
if (class_exists($className)) {
Varien_Profiler::start('CORE::create_object_of::'.$className);
$obj = new $className($constructArguments);
Varien_Profiler::stop('CORE::create_object_of::'.$className);
return $obj;
} else {
#throw Mage::exception('Mage_Core', Mage::helper('core')->__('Model class does not exist: %s.', $modelClass));
return false;
}
}
...

Categories