[PHP] include() and duplicate function definition
Hi, :-) I'm making a child theme for WordPress. I need to rewrite one function defined in ../sometheme/functions/actions.php and put that rewritten function in wp-content/themes/sometheme-child/functions/actions.php. But I want to preserve ../sometheme/functions/actions.php unchanged in any way. (Future theme updates would just overwrite any changes I made.) So, in my new actions.php, I put an include followed by the replacement function definition, named identically to the one I want to replace: ?php include '../sometheme/functions/actions.php'; function foo($arg_1, $arg_2, /* ..., */ $arg_n) { echo All my new code.\n; } ? Because this duplicate foo() function definition comes after the foo() defined in the included file, does it replace the included foo()? Or how can I achieve what I want? Big thanks in advance for any suggestions. :-) David -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] include() and duplicate function definition
On Wed, 3 Nov 2010 17:59:06 +0800, David Nelson comme...@traduction.biz wrote: Hi, :-) I'm making a child theme for WordPress. I need to rewrite one function defined in ../sometheme/functions/actions.php and put that rewritten function in wp-content/themes/sometheme-child/functions/actions.php. But I want to preserve ../sometheme/functions/actions.php unchanged in any way. (Future theme updates would just overwrite any changes I made.) So, in my new actions.php, I put an include followed by the replacement function definition, named identically to the one I want to replace: ?php include '../sometheme/functions/actions.php'; function foo($arg_1, $arg_2, /* ..., */ $arg_n) { echo All my new code.\n; } ? Because this duplicate foo() function definition comes after the foo() defined in the included file, does it replace the included foo()? Or how can I achieve what I want? Big thanks in advance for any suggestions. :-) David As far as I know it is not possible to overwrite functions in PHP (unless you use runkit, apd). Inside classes this is possible. But that's not the case here. Why do the functions have to be equally named? Try to create a new function and call the original function from there if needed... foo2() { foo() } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] include() and duplicate function definition
Hi Thijs, :-) On Wed, Nov 3, 2010 at 18:18, Thijs Lensselink d...@lenss.nl wrote: As far as I know it is not possible to overwrite functions in PHP (unless you use runkit, apd). Inside classes this is possible. But that's not the case here. Why do the functions have to be equally named? If the functions aren't named the same, my replacement function will never get called by the code that uses the WordPress theme code... Try to create a new function and call the original function from there if needed... Sadly, it wouldn't work for the above reason... But thanks for your answer. :-) David Nelson -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] include() and duplicate function definition
You can check with function_exists to see if a function is already defined. If not, create it. Regards Peter On Nov 3, 2010 11:40 AM, David Nelson comme...@traduction.biz wrote: Hi Thijs, :-) On Wed, Nov 3, 2010 at 18:18, Thijs Lensselink d...@lenss.nl wrote: As far as I know it is not possible to overwrite functions in PHP (unless you use runkit, apd). Inside classes this is possible. But that's not the case here. Why do the functions have to be equally named? If the functions aren't named the same, my replacement function will never get called by the code that uses the WordPress theme code... Try to create a new function and call the original function from there if needed... Sadly, it wouldn't work for the above reason... But thanks for your answer. :-) David Nelson -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] include() and duplicate function definition
Hi Peter, :-) On Wed, Nov 3, 2010 at 18:44, Peter Lind peter.e.l...@gmail.com wrote: You can check with function_exists to see if a function is already defined. If not, create it. The function is definitely already defined, I just need to replace it without touching the file in which it's defined... David Nelson -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] include() and duplicate function definition
That's not going to happen. My point was you could check in the original file if the function is defined and if not then define it. On Nov 3, 2010 11:55 AM, David Nelson comme...@traduction.biz wrote: Hi Peter, :-) On Wed, Nov 3, 2010 at 18:44, Peter Lind peter.e.l...@gmail.com wrote: You can check with function_exists to see if a function is already defined. If not, create it. The function is definitely already defined, I just need to replace it without touching the file in which it's defined... David Nelson
Re: [PHP] include() and duplicate function definition
Hi, :-) On Wed, Nov 3, 2010 at 19:29, Peter Lind peter.e.l...@gmail.com wrote: That's not going to happen. My point was you could check in the original file if the function is defined and if not then define it. OK, thanks, Thijs and Peter, it looks like I'm trying to do something that is not currently possible in PHP. Time for some lateral thinking. :-) David Nelson -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] include() and duplicate function definition
On Wed, 3 Nov 2010 19:53:52 +0800, David Nelson comme...@traduction.biz wrote: Hi, :-) On Wed, Nov 3, 2010 at 19:29, Peter Lind peter.e.l...@gmail.com wrote: That's not going to happen. My point was you could check in the original file if the function is defined and if not then define it. OK, thanks, Thijs and Peter, it looks like I'm trying to do something that is not currently possible in PHP. Time for some lateral thinking. :-) David Nelson David, I re-read your original post. And noticed you include the function inside your child action.php Is there a special reason for that? You want to overwrite the original function in a child theme. probably to get different functionality. So why do you need the original function? Just create your action.php and define the same function. // include '../sometheme/functions/actions.php'; function foo($arg_1, $arg_2, /* ..., */ $arg_n) { echo All my new code.\n; } It's code duplication. But i don't think themes should have dependencies to one an other. You could also create a actions.php file outside the themes folder. wp-content/shared-functions/action.php And then in your themes do: theme 1 include shared-function/action.php; foo(); theme 2 include shared-function/action.php; foo(); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Execute a php page and don't wait for it to finish
On 19 October 2010 18:50, Ferdi ferdinan...@printo.in wrote: Hi List, I have a php page that updates data from one database to another when it is run. My query is, how can I trigger the execution of this update page from another php / javascript without the calling page having to wait for the update page to finish? Basically, I think the update page needs to use: ignore_user_abort(1); set_time_limit(0); // I don't think the script will take more than 1 min. At the other end I found this: 1) http://www.mindraven.com/blog/php/run-a-php-script-in-the-background-using-ajax/ 2) On that page a user suggested using *pclose(popen(‘/usr/bin/php /path/to/something.php /dev/null ’, ‘r’)* **However, I need this to be usable on windows servers also. 3) Finally, would pcntl_exec, pcntl_fork, exec or something be useful for me? Which of the above 3 options is the better one? Other suggestions are welcome :) Hi List, Sorry this took so long, but I wanted to close the loop (and maybe ease some one else's trouble :-)). I didn't think much about the die(header('Location: run_this_even_if_user_aborts.php')) call I was actually using to get this working. When I carefully looked up php.net for header, I realised it was a browser redirect! Now wonder the script would work some times but not always. It's clear now that every time the script worked was because I waited long enough for the browser to be redirected before killing the page. I finally settled on using jquery's ajax calls. Thanks once again to the repliers. Ferdi
Re: [PHP] Integrating zend-facebook error
Can you paste a dump of complete error stack ? On Sun, Oct 31, 2010 at 10:12 PM, Yuri Yarlei yuriyar...@gmail.com wrote: Hi, I'm trying to integrate facebook to show the wall in a site. ok, i generate the auth_token here: https://login.facebook.com/code_gen.php?api_key=API_KEYv=1.0 And put the rest connection configuration here: $facebookArr = array( appapikey = $appapikey, appidkey = $appidkey, appsecret = $appsecret, appcallbackurl = $appcallbackurl, 'cookie' = true, 'token' = $token ); $fb = new FacebookRestClient($facebookArr['appapikey'], $facebookArr['appsecret']); $result = $fb-call_method('facebook.auth.getSession', array('auth_token' =$facebookArr['token'], 'generate_session_secret' = true)); Its work, but only the first time, if i refresh i get this exception: exception 'FacebookRestClientException' with message 'Invalid parameter' If i generate the token again, its work for the first time again. Please someone have any recent tutorial to integrate facebook to some php site? Atenciosamente, Yuri Yarlei. www.yuriyarlei.net (under construction) Programmer PHP, JAVA, CSS, ORACLE 10g, PostgreSQL; Next step is the SCJP. Se você ainda não esta com dor de cabeça, é por que ainda cabe um pouco mais de conhecimento. -- Regards, Nitesh Nandy
[PHP] include() and duplicate function definition
Hi Thijs, :-) On Wed, Nov 3, 2010 at 20:38, Thijs Lensselink d...@lenss.nl wrote: I re-read your original post. And noticed you include the function inside your child action.php Is there a special reason for that? You want to overwrite the original function in a child theme. probably to get different functionality. So why do you need the original function? Just create your action.php and define the same function. It's a WordPress issue. When theme updates become available from the original vendor, you can update them from within the admin backend. In that case, any hacks you've applied (such as removing a function) get overwritten. So the evangelized solution is to create a child theme. The child theme incorporates only files that you've added or changed, with the original parent theme being used for all others. Easy peasy if you want to *add* a function. But, if you want to *modify* a function, you're faced with the problem of the original function still being present in the parent theme files and of your having to define a function of the same name in your child theme (if you change the function name, you then have to hack other code further upstream, and the work involved becomes not worth the bother). Somehow, I would need to make my hacked function *replace* the original function, *without* touching the original function... It seems like that's not possible and I'll have to find another solution... unless my explanation gives you any good ideas? Just to put the dots on the I's, the original actions.php contains a lot of *other* functions that I don't want to touch, and that I do want to leave exposed to the updates process. It's just one single function I want to hack... Sticky problem, huh? :-) In any case, thanks for your kind help, :-) David Nelson P.S. Sorry about the direct mails: I keep forgetting to hit the Replly to all button. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] include() and duplicate function definition
On Thu, 2010-11-04 at 00:00 +0800, David Nelson wrote: Hi Thijs, :-) On Wed, Nov 3, 2010 at 20:38, Thijs Lensselink d...@lenss.nl wrote: I re-read your original post. And noticed you include the function inside your child action.php Is there a special reason for that? You want to overwrite the original function in a child theme. probably to get different functionality. So why do you need the original function? Just create your action.php and define the same function. It's a WordPress issue. When theme updates become available from the original vendor, you can update them from within the admin backend. In that case, any hacks you've applied (such as removing a function) get overwritten. So the evangelized solution is to create a child theme. The child theme incorporates only files that you've added or changed, with the original parent theme being used for all others. Easy peasy if you want to *add* a function. But, if you want to *modify* a function, you're faced with the problem of the original function still being present in the parent theme files and of your having to define a function of the same name in your child theme (if you change the function name, you then have to hack other code further upstream, and the work involved becomes not worth the bother). Somehow, I would need to make my hacked function *replace* the original function, *without* touching the original function... It seems like that's not possible and I'll have to find another solution... unless my explanation gives you any good ideas? Just to put the dots on the I's, the original actions.php contains a lot of *other* functions that I don't want to touch, and that I do want to leave exposed to the updates process. It's just one single function I want to hack... Sticky problem, huh? :-) In any case, thanks for your kind help, :-) David Nelson P.S. Sorry about the direct mails: I keep forgetting to hit the Replly to all button. I am curious on how this would work, if for some reason they were using a different template? the function you want to overwrite, wont be used, and therefore, wouldn't your app/template/whatever be updated improperly than waht you expect it to be? Just curious... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] include() and duplicate function definition
Hi guys, :-) Just FYI, I got this answer from the theme dev: David, You don't need the include statement. If you create your function in wp-content/themes/suffusion-child/functions.php it will get automatically included. Secondly, using the same function name wouldn't work, because it would require me to encase the original function definition in actions.php in a function_exists clause. I would suggest using a different function name, then using remove_action to remove the older action and add_action to add the new action. (http://www.aquoid.com/forum/viewtopic.php?f=4t=3070) I'm not yet confident about how to actually implement this in code... Any tips or advice would be gratefully heard. On Thu, Nov 4, 2010 at 00:13, Steve Staples sstap...@mnsi.net wrote: I am curious on how this would work, if for some reason they were using a different template? the function you want to overwrite, wont be used, and therefore, wouldn't your app/template/whatever be updated improperly than waht you expect it to be? Steve, maybe the above informs? In any case, the function to be overwritten is likely to remain fairly stable... All the best, :-) David Nelson -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Apache mod_pagespeed
Guys, Google announced this morninghttp://googlewebmastercentral.blogspot.com/2010/11/make-your-websites-run-faster.htmltheir mod_pagespeed http://code.google.com/speed/page-speed/docs/module.html to improve Apache's performance. It really looks promising, what do you guys think? Me and Daniel Brown will be running some tests with it, let us know if you'd like to join us. :) Google mentions 2x faster loading times, but they don't mention CPU cost. What do you think it will break? Cheers, Thiago Henrique Pojda +55 41 8856-7925
Re: [PHP] Apache mod_pagespeed
Thiago, I would like to join this. Let me know how I can help you with this. Please be explicit with your requests so that we can totally test it and see if it could pose any risk to acceleration services provided by CDNs. Regards, Shreyas On Wed, Nov 3, 2010 at 11:51 PM, Thiago H. Pojda thiago.po...@gmail.comwrote: Guys, Google announced this morning http://googlewebmastercentral.blogspot.com/2010/11/make-your-websites-run-faster.html their mod_pagespeed http://code.google.com/speed/page-speed/docs/module.html to improve Apache's performance. It really looks promising, what do you guys think? Me and Daniel Brown will be running some tests with it, let us know if you'd like to join us. :) Google mentions 2x faster loading times, but they don't mention CPU cost. What do you think it will break? Cheers, Thiago Henrique Pojda +55 41 8856-7925 -- Regards, Shreyas Agasthya
Re: [PHP] Apache mod_pagespeed
On Wed, Nov 3, 2010 at 14:48, Shreyas Agasthya shreya...@gmail.com wrote: Thiago, I would like to join this. Let me know how I can help you with this. Please be explicit with your requests so that we can totally test it and see if it could pose any risk to acceleration services provided by CDNs. I've yet to read the specs behind it (I was out of the office), but from the overview I did see, it should not only be of no detriment to CDNs. In fact, Google is working with an existing company, Cotendo, to integrate the core into their CDN. -- /Daniel P. Brown Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting (866-) 725-4321 http://www.parasane.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Apache mod_pagespeed
They are doing a preso about it @ ApacheCon. On Wed, Nov 03, 2010 at 03:34:01PM -0400, Daniel P. Brown wrote: On Wed, Nov 3, 2010 at 14:48, Shreyas Agasthya shreya...@gmail.com wrote: Thiago, I would like to join this. Let me know how I can help you with this. Please be explicit with your requests so that we can totally test it ?and see if it could pose any risk to acceleration services provided by CDNs. I've yet to read the specs behind it (I was out of the office), but from the overview I did see, it should not only be of no detriment to CDNs. In fact, Google is working with an existing company, Cotendo, to integrate the core into their CDN. -- /Daniel P. Brown Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting (866-) 725-4321 http://www.parasane.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- === Jim Jagielski [|] j...@jagunet.com [|] http://www.jaguNET.com/ Great is the guilt of an unnecessary war ~ John Adams -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Problems converting strings with 0 to integer
Hi, I have a text file (utf-8 encoded) which contains lines with numbers and text separated by \t. I need to convert the numbers that contains 0 (at left) to integers. For some reason one line that contains 0002 is casted to 0 instead of 2. Bellow the output of the cast (int) $field[0] where I get this from explode each line. 0 0002 4 0004
Re: [PHP] Problems converting strings with 0 to integer
To exclude unexcepted behavior in case of wrongly formated input data, it would be much better to use such type-casting method: intval(ltrim(trim($inStr), '0')) 2010/11/3, Nicholas Kell n...@monkeyknight.com: On Nov 3, 2010, at 4:22 PM, robert mena wrote: Hi, I have a text file (utf-8 encoded) which contains lines with numbers and text separated by \t. I need to convert the numbers that contains 0 (at left) to integers. For some reason one line that contains 0002 is casted to 0 instead of 2. Bellow the output of the cast (int) $field[0] where I get this from explode each line. 0 0002 4 0004 My first guess is wondering how you are grabbing the strings from the file. Seems to me like it would just drop the zeros on the left by default. Are you including the \t in the string by accident? If so, that may be hosing it. Otherwise, have you tried ltrim on it? Ex: $_castableString = ltrim($_yourString, '0'); // Now cast -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Problems converting strings with 0 to integer
On Nov 3, 2010, at 4:22 PM, robert mena wrote: Hi, I have a text file (utf-8 encoded) which contains lines with numbers and text separated by \t. I need to convert the numbers that contains 0 (at left) to integers. For some reason one line that contains 0002 is casted to 0 instead of 2. Bellow the output of the cast (int) $field[0] where I get this from explode each line. 0 0002 4 0004 My first guess is wondering how you are grabbing the strings from the file. Seems to me like it would just drop the zeros on the left by default. Are you including the \t in the string by accident? If so, that may be hosing it. Otherwise, have you tried ltrim on it? Ex: $_castableString = ltrim($_yourString, '0'); // Now cast -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php