![]() |
|
MySql Error when including template-functions - Printable Version +- ZenphotoCMS Forum (https://forum.zenphoto.org) +-- Forum: Support (https://forum.zenphoto.org/forum-1.html) +--- Forum: General support (https://forum.zenphoto.org/forum-4.html) +--- Thread: MySql Error when including template-functions (/thread-6278.html) Pages:
1
2
|
MySql Error when including template-functions - jak - 2010-01-30 The problem is that if you use require_once inside a function variables that are declared in global scope are no longer global. You will have to apply similar fixes to other files:zp-core/lib-GD.phpglobal $_lib_GD_info; zp-core/functions-basic.phpglobal $_zp_conf_vars, $_zp_error, $_zp_imagick_present, $_zp_imagick_present, zp-core/functions.phpglobal $_zp_plugin_scripts, $_zp_loaded_plugins, $_zp_flash_player, zp-core/template-functions.phpglobal $_zp_conf_vars, $_zp_gallery; zp-core/lib-utf8.phpglobal $_zp_UTF8; HTH MySql Error when including template-functions - sbillard - 2010-01-30 There is really no cause to place the require_once within the function. So why go throught all this work when you will probably overlook something and things will not work anyway. Just place the require_once in the script that contains the function rather than within it. MySql Error when including template-functions - jak - 2010-01-30 This is indeed the best workaround. I think it might be wort to mention it on this page: http://www.zenphoto.org/2009/12/zenphoto-as-a-plug-in-using-zenphoto-functions-from-outside-zenphoto/ BTW: I don't want to sound like a smartass, but the problem are not the function definitions. The problem is the assumption that variables in a .php file that are not inside a function are on the global scope. Normally that is the case but they are not as soon as require_once (or require) is used inside a function. In that case the variables are on the local scope. I am sure sbillard knows this, but many people do not. It was definitely not obvious to the person that wrote the article I mentioned above. An Example:
` MySql Error when including template-functions - sbillard - 2010-01-30 Are you saying that the Wordpress problem is that the require_once calls are within a function call? (I know nothing of Wordpress.) MySql Error when including template-functions - jak - 2010-01-30 I did not try it using wordpress - but it sure looks that way. The cause for this is that zp-config.php assumes that $_zp_conf_vars is global. If you use require_once inside a function, the $_zp_conf_vars in zp-config is a local variable (or something like that - it definitely is no longer global) and the data saved to it can not be accessed via the global variable of the same name. Ths is tried inside functions-db.php --> no DB connection is possible. MySql Error when including template-functions - sbillard - 2010-01-31 I suppose that could have been something WP changed recently--the plugin stuff used to work. But PHP should also be throwing errors for the undefined $_zp_conf_vars. Maybe WP also supresses those? MySql Error when including template-functions - sbillard - 2010-01-31 I suppose that could have been something WP changed recently--the plugin stuff used to work. But PHP should also be throwing errors for the undefined $_zp_conf_vars. Maybe WP also supresses those? I have little hope that anyone could keep up with the Zenphoto globals well enough to make it so that the files can be required from within a procedure. I hope that there is a different solution available for Wordpress. MySql Error when including template-functions - acrylian - 2010-01-31 The plugin way indeed worked reportley with older Wordpress installs for quite some time. I think it started with WP 2.8 that it stopped. We did not have the time/resource to investigate as we concentrate on Zenphoto as standalone script. But thanks for doing that. This indeed gives a hint why it does not work anymore. As sbillard said there is probably no convenient way to workaround this. MySql Error when including template-functions - jak - 2010-01-31 I think I found the relevant part in the wordpress source: I would suggest putting the require_once('path/to/zenphoto/zp-core/template-functions.php') inside wp-config - it seems like this file is included directly (not form inside a function). I still think that it might be worth it to at least think about a long term solution: HTH MySql Error when including template-functions - sbillard - 2010-01-31 I am afraid that there are quite a large number of variables that are required to be global. As I said, the probablity of getting this change right is pretty small. Besides which, it is not actually a zenphoto issue. Zenphoto has been designed to be a stand-alone system. It is possible to use parts (but certainly not all) of it from other systems, but only if you properly set up its environment. MySql Error when including template-functions - jak - 2010-01-31 I completely understand that you focus on Zenphoto as standalone. I just want to note that global variables are not a problem, the problem occurs only when the global variable is accessed without declaring it to be global. Note that in the following example the acces to $otherVar works as expected.
MySql Error when including template-functions - sbillard - 2010-01-31 I understand. However there is no requirement to declare a varaible global when it is used outside of a function. It would perhaps be nice if PHP had an option to require this, but it does not so far as I know. Thus, when a script sets up a variable it normally will not also declare it globally. If you take a look at the scripts you will see that there are quite a few such variables. Again, I reiterate. The probability of success in this venture is small. The effort is large. And the result is not directly applicable to Zenphoto. Anyone wishing to instantiate Zenphoto from within a function is welcome to create a script that declares these variables and include it with the Zenphoto ones. This is not an effor that has any priority with me. |