[PHP] get calling function name
Greetings, is there a way (i swear i saw it in the documentation at one point) to get the name of the calling scope (or function) from within another function? eg. function a() { b(); } function b() { echo "the calling function is: " . func_caller(); } a(); where this would print the calling function is a (i made func_caller() up) I hope this is clear, and i hope there is a quick solution and i just can't find it in the documentation. Thanks, dk
Re: [PHP] get calling function name
Stut wrote: On 9 Dec 2008, at 19:37, Daniel Kolbo wrote: is there a way (i swear i saw it in the documentation at one point) to get the name of the calling scope (or function) from within another function? eg. function a() { b(); } function b() { echo "the calling function is: " . func_caller(); } a(); where this would print the calling function is a (i made func_caller() up) I hope this is clear, and i hope there is a quick solution and i just can't find it in the documentation. http://php.net/debug_backtrace -Stut Stut, that'll do the trick. thanks, dK
[PHP] file_exists and wildcard/regex
What is the preferred method with php to test and see if a file [pattern] exists? For example, i only need to search in one directory, that may have any number of files named such as afile1.txt, afile2.txt, afile3.txt, And also, bfile1.txt, bfile2.txt, bfile3.txt, ... I want to see if any such file 'family' exists. That is, i want to see if there is any file named bfile[1-9][0-9]+.txt. I don't care which bfile number exists, i just want to know if any bfile exists. I hope this is clear enough, if not let me know. thanks, dK
Re: [PHP] file_exists and wildcard/regex
Daniel Kolbo wrote: What is the preferred method with php to test and see if a file [pattern] exists? For example, i only need to search in one directory, that may have any number of files named such as afile1.txt, afile2.txt, afile3.txt, And also, bfile1.txt, bfile2.txt, bfile3.txt, ... I want to see if any such file 'family' exists. That is, i want to see if there is any file named bfile[1-9][0-9]+.txt. I don't care which bfile number exists, i just want to know if any bfile exists. I hope this is clear enough, if not let me know. thanks, dK After some more research it seems my options are: 1) loop through the directory contents 2) use scandir (then search the resulting array) 3) use glob. I am not familiar with the glob pattern library, it does not seem like i have the full power of regex when using glob is this correct? Also, searching the whole filesystem seems...overkill. What do you suggest, is there a 4th option? thanks, dK
[PHP] Re: file_exists and wildcard/regex
Maciek Sokolewicz wrote: Daniel Kolbo wrote: What is the preferred method with php to test and see if a file [pattern] exists? For example, i only need to search in one directory, that may have any number of files named such as afile1.txt, afile2.txt, afile3.txt, And also, bfile1.txt, bfile2.txt, bfile3.txt, ... I want to see if any such file 'family' exists. That is, i want to see if there is any file named bfile[1-9][0-9]+.txt. I don't care which bfile number exists, i just want to know if any bfile exists. I hope this is clear enough, if not let me know. thanks, dK glob() http://www.php.net/glob How portable is glob? How fast is glob? Being that it searches through the entire filesystem, this could potentially take a long time (like if i have wildcards early in the filepath pattern and lots of matches) correct? If my file variations (wildcards) are just at the end of of the filepaths and i don't have more than 1000 files in the directory then will I most likely be 'alright' with glob (in terms of time)? I have probably spent more time now 'considering' the time implications of glob, than glob actually would consume when operating... Thanks for the quick response/solutions. dK
[PHP] utf8 php howto?
Hello, I have a text file encoded in utf-8. i am using fopen/fgets/echo etc.. how do i display these utf8 characters from the file on the web? I have tried different combinations of header("Content-Type: text/html; charset=iso-8859-1"); header("Content-Type: text/html; charset=utf-8") and utf8_decode/utf8_encode functions I can't seem to get the characters from the file to display as non-giberish on the web. if i set the charset=utf8, and type the unique characters in directly to my document (hard coded) and save the document as utf8, then the characters display properly on the web. examples: 1) save file as utf-8, web produces correct characters [type special characters here using russian keyboard layout] 2) save file as ASCI, web produces [giberish] 3) save file as utf-8, web produces [giberish] Thanks for your help, dK
Re: [PHP] utf8 php howto?
Daniel Kolbo wrote: Hello, I have a text file encoded in utf-8. i am using fopen/fgets/echo etc.. how do i display these utf8 characters from the file on the web? I have tried different combinations of header("Content-Type: text/html; charset=iso-8859-1"); header("Content-Type: text/html; charset=utf-8") and utf8_decode/utf8_encode functions I can't seem to get the characters from the file to display as non-giberish on the web. if i set the charset=utf8, and type the unique characters in directly to my document (hard coded) and save the document as utf8, then the characters display properly on the web. examples: 1) save file as utf-8, web produces correct characters [type special characters here using russian keyboard layout] 2) save file as ASCI, web produces [giberish] 3) save file as utf-8, web produces [giberish] Thanks for your help, dK found a solution: save the .php file as ASCII thanks, dK
Re: [PHP] Re: CLI in background on windows
Ondrej Kulaty wrote: What about to try run it as service? I don't know exactly how to do that but service programs run in background on my Win XP ""Fanda"" pí¹e v diskusním pøíspìvku news:7d.3d.09584.c2f7a...@pb1.pair.com... Hi, I am looking for some method, how to run php cli script on background in windows. It should be started by windows task manager. Do you have any idea? Thans, Fanda Just did a quick search: http://www.tacktech.com/display.cfm?ttid=197 looking at other services, they have parameters so you could probably do this with php.exe pretty cool idea...hmm...what can i do with this. note: start->run:services.msc will open your services manager hTh dK
Re: [PHP] Architecture patterns in PHP
Michael C. Yates wrote: Hey, How do you structure your web applications? I am thinking in terms of separating presentation and logic. How is that done in PHP? And how many architecture patterns are there? Thanks Micheal C. Yates I am an amateur programmer, so take my comments with a grain of salt (i haven't done heavy traffic long term projects). Having read through this thread no one has of yet mentioned Smarty.net http://smarty.net/ . Smarty is a template engine. It allows presentation to be separated with logic. I like it cuz my site designes usually end up looking like a 3rd grader designed it and you need some sorta special glasses to protect your eyes. However, i can do some solid logic coding (query DBs and whatnot). So smarty has been highly prized by me in my projects. But that is all i am doing is 'projects', those that usually lost money. But this is not because of smarty. Without smarty i wouldn't have even been able to get going. Also, it cleans up the code if you stick to the division principles. my USD 0.02$ which is a lot less now than it used to be... :( dK
[PHP] Remote File Variable Injection Safety?
Hello, suppose there is a file at http://otherhost.com/remote.php that looks like this: Suppose i executed the following php file at http://myhost.com/local.php http://otherhost.com/remote.php";); ?> Is there any way to get local.php to display "You are in", by only modifying local.php? That is, is there a way to set $safe_flag on the remote host as one requests a file from the remote host from within local.php? I have genuine, academic, non-belligerent intentions when asking this question. Thanks, dK
Re: [PHP] Re: Remote File Variable Injection Safety?
Shawn McKenzie wrote: Daniel Kolbo wrote: Hello, suppose there is a file at http://otherhost.com/remote.php that looks like this: Suppose i executed the following php file at http://myhost.com/local.php http://otherhost.com/remote.php";); ?> Is there any way to get local.php to display "You are in", by only modifying local.php? That is, is there a way to set $safe_flag on the remote host as one requests a file from the remote host from within local.php? I have genuine, academic, non-belligerent intentions when asking this question. Thanks, dK local.php http://otherhost.com/remote.php";); ?> The proposed method does not work, as the script returned from remote.php is "hacking attempt", because $safe_flag is in the scope of myhost.com and not otherhost.com. dK
Re: [PHP] Re: Remote File Variable Injection Safety?
Stuart wrote: 2009/1/7 Shawn McKenzie : Daniel Kolbo wrote: Hello, suppose there is a file at http://otherhost.com/remote.php that looks like this: Suppose i executed the following php file at http://myhost.com/local.php http://otherhost.com/remote.php";); ?> Is there any way to get local.php to display "You are in", by only modifying local.php? That is, is there a way to set $safe_flag on the remote host as one requests a file from the remote host from within local.php? I have genuine, academic, non-belligerent intentions when asking this question. local.php http://otherhost.com/remote.php";); ?> If the remote side is returning the code rather than running it then anyone can see exactly what to do to get it to work. There is no security there. OP: Does otherhost.com run the code or return it? -Stuart otherhost.com runs the code. dK
Re: [PHP] Remote File Variable Injection Safety?
c...@l-i-e.com wrote: If register_globals is "on" (ewww!) at otherhost.com, then "?safe_flag" on the URL will get in. This is one of the reasons why register_globals should be OFF. NOTE: The code you gave does not describe the circumstances whereby $safe_flag is "set". There could be all manner of other issues around that code that we cannot address without seeing more. There is no other code. This is an example I created to help me understand finer points of PHP. thanks, dK
[PHP] PHP, Smarty, and Text
Hello, I've been using PHP and Smarty for several years now and I am happy with this "division" of data from presentation. With this philosophy in mind, i am a bit perplexed as to how to handle the text on my sites. That is, the text is data, so i am motivated to store the text in a database, files, or the like, but then text is loaded with little markup nuances (random italics/weight/colors, etc...) that make template design rather ugly. This motivates me to put markup (maybe even my own brand of markup) around the text, and to store this markup-text combination in a database. But I don't like this either, because a lot of the people writing the content/text know word/writer not markup. So i am motivated to have them save their text as .html, and I parse this file and modify accordingly. However, i don't like this either as not all word/writer styles are 1-to-1 with CSS. Without any options I am back to thinking "hard code" the text with markup in included templates, but it hurts just thinking of updating/modifying. I have looked (briefly) at Web Content Management Systems, but this seems like overkill really, maybe i'm ignorant. What would the community suggest? The text can take on many forms, introduction text, about text, product information, articles, blurbs, (some changes daily, some doesn't) etc...where does all this text live in 'properly' designed site. Thanks in advance, dK
Re: [PHP] PHP, Smarty, and Text
Phpster wrote: What about stripping out all the 'nuances' and just reducing it to just the text where you then control the display and using your templates and css? Bastien Sent from my iPod On Jan 13, 2009, at 9:49 PM, Daniel Kolbo wrote: Hello, I've been using PHP and Smarty for several years now and I am happy with this "division" of data from presentation. With this philosophy in mind, i am a bit perplexed as to how to handle the text on my sites. That is, the text is data, so i am motivated to store the text in a database, files, or the like, but then text is loaded with little markup nuances (random italics/weight/colors, etc...) that make template design rather ugly. This motivates me to put markup (maybe even my own brand of markup) around the text, and to store this markup-text combination in a database. But I don't like this either, because a lot of the people writing the content/text know word/writer not markup. So i am motivated to have them save their text as .html, and I parse this file and modify accordingly. However, i don't like this either as not all word/writer styles are 1-to-1 with CSS. Without any options I am back to thinking "hard code" the text with markup in included templates, but it hurts just thinking of updating/modifying. I have looked (briefly) at Web Content Management Systems, but this seems like overkill really, maybe i'm ignorant. What would the community suggest? The text can take on many forms, introduction text, about text, product information, articles, blurbs, (some changes daily, some doesn't) etc...where does all this text live in 'properly' designed site. Thanks in advance, dK Hello Bastien, The difficulty with implementing your suggestions is that say in a paragraph of text that has random bold or italics (etc...) (as determined by the one drafting the text), how would i recover these bold/italics if i remove them? dK
Re: [PHP] PHP, Smarty, and Text
Robert Cummings wrote: On Tue, 2009-01-13 at 18:18 -1000, Daniel Kolbo wrote: Phpster wrote: What about stripping out all the 'nuances' and just reducing it to just the text where you then control the display and using your templates and css? Bastien Sent from my iPod On Jan 13, 2009, at 9:49 PM, Daniel Kolbo wrote: Hello, I've been using PHP and Smarty for several years now and I am happy with this "division" of data from presentation. With this philosophy in mind, i am a bit perplexed as to how to handle the text on my sites. That is, the text is data, so i am motivated to store the text in a database, files, or the like, but then text is loaded with little markup nuances (random italics/weight/colors, etc...) that make template design rather ugly. This motivates me to put markup (maybe even my own brand of markup) around the text, and to store this markup-text combination in a database. But I don't like this either, because a lot of the people writing the content/text know word/writer not markup. So i am motivated to have them save their text as .html, and I parse this file and modify accordingly. However, i don't like this either as not all word/writer styles are 1-to-1 with CSS. Without any options I am back to thinking "hard code" the text with markup in included templates, but it hurts just thinking of updating/modifying. I have looked (briefly) at Web Content Management Systems, but this seems like overkill really, maybe i'm ignorant. What would the community suggest? The text can take on many forms, introduction text, about text, product information, articles, blurbs, (some changes daily, some doesn't) etc...where does all this text live in 'properly' designed site. Thanks in advance, dK Hello Bastien, The difficulty with implementing your suggestions is that say in a paragraph of text that has random bold or italics (etc...) (as determined by the one drafting the text), how would i recover these bold/italics if i remove them? Strip all tags except bold and italics. Then replace with and with since the former tags are deprecated. If semantic meaning is not intended by and then replace with and and create those CSS styles. Cheers, Rob. Yes, okay, but who is putting the tags there in the first place? The writers who are drafting these in word/writer are not marking them up...So say I put tags around the required items, then when the writer goes to edit, they are going to say "what is all this", it is not a 'seamless' division. I am really looking for a three fold division, 1) Logic/data, 2) presentation, and 3) text. Just like the logic side doesn't concern itself with presentation, I'd like the writers to not be concerned with presentation/markup either (except for using the styles available in word/writer). It seems a bit tricky...the writer is providing the data without PHP knowledge and some styles without Smarty knowledge. The question is how does one bridge this strange gap in a manageable and easily scalable way? dK
[PHP] Mailing list rules?
Hello, Is it okay for me to post a message looking for programmers willing to help out with a php project? Thanks, dK
[PHP] Secure File Paths, File System
Hello PHPers, I am quite ignorant about file system security. I was hoping you all could help me understand things. How does one restrict php script from going (reading, writing) files in the file system? As I see it, a php programmer could change the include_path, with ini_set(), use "../" etc..., and browse all the files on the server to which the php engine has access. This would clearly not be acceptable to a web host company, so how do most hosts restrict this kind of behaviour? Now, suppose i only have php access to my 'files' as defined by my host somehow. (again, my first part of the question is how do they do this?). Is it possible for me to further restrict this file accessibility for different sub-folders? Let me provide an example folder hierarchy and user scenario. Suppose there are two php programmers (me and you). I want full access, but I want to restrict you to your subdomain (subdomain2). +AllUsers (me and you) +Domain1 ++Subdomain1 (me only) ++Subdomain2 (me and you) ++SharedDomain (me and you) +ServerFile1 (me only) +ServerFile2 (me only) +SecretFile (no user) Thanks for helping understand how to restrict/limit different php programmers from going into places I'd rather them not go. dK
Re: [PHP] Re: Secure File Paths, File System - (simplified question)
Shawn McKenzie wrote: Daniel Kolbo wrote: Hello PHPers, I am quite ignorant about file system security. I was hoping you all could help me understand things. How does one restrict php script from going (reading, writing) files in the file system? As I see it, a php programmer could change the include_path, with ini_set(), use "../" etc..., and browse all the files on the server to which the php engine has access. This would clearly not be acceptable to a web host company, so how do most hosts restrict this kind of behaviour? Now, suppose i only have php access to my 'files' as defined by my host somehow. (again, my first part of the question is how do they do this?). Is it possible for me to further restrict this file accessibility for different sub-folders? Let me provide an example folder hierarchy and user scenario. Suppose there are two php programmers (me and you). I want full access, but I want to restrict you to your subdomain (subdomain2). +AllUsers (me and you) +Domain1 ++Subdomain1 (me only) ++Subdomain2 (me and you) ++SharedDomain (me and you) +ServerFile1 (me only) +ServerFile2 (me only) +SecretFile (no user) Thanks for helping understand how to restrict/limit different php programmers from going into places I'd rather them not go. dK Two methods come to mind, chroot and just setting perms for specific dirs. Hello, 1) chroot I don't understand how to specify to the php engine to chroot upon different scripts being executed (scripts that i don't control). Would you please clarify? 2)perms The php engine is what has access to specific dirs (not users, scripts,). That i know of, the php engine doesn't allow per user permissions. That is, it is one engine, one set of perms. Are you suggesting i have a separate php engine for each user? 3) Maybe i can simplify this question: How does a hosting company, in a shared virtual host server environment, prevent all their clients (php programmers) from snooping into all the other clients' folders? I am assuming we are all using the same php engine, as it is a shared apache host.
Re: [PHP] Re: Secure File Paths, File System - (simplified question)
Shawn McKenzie wrote: Daniel Kolbo wrote: Shawn McKenzie wrote: Daniel Kolbo wrote: Hello PHPers, I am quite ignorant about file system security. I was hoping you all could help me understand things. How does one restrict php script from going (reading, writing) files in the file system? As I see it, a php programmer could change the include_path, with ini_set(), use "../" etc..., and browse all the files on the server to which the php engine has access. This would clearly not be acceptable to a web host company, so how do most hosts restrict this kind of behaviour? Now, suppose i only have php access to my 'files' as defined by my host somehow. (again, my first part of the question is how do they do this?). Is it possible for me to further restrict this file accessibility for different sub-folders? Let me provide an example folder hierarchy and user scenario. Suppose there are two php programmers (me and you). I want full access, but I want to restrict you to your subdomain (subdomain2). +AllUsers (me and you) +Domain1 ++Subdomain1 (me only) ++Subdomain2 (me and you) ++SharedDomain (me and you) +ServerFile1 (me only) +ServerFile2 (me only) +SecretFile (no user) Thanks for helping understand how to restrict/limit different php programmers from going into places I'd rather them not go. dK Two methods come to mind, chroot and just setting perms for specific dirs. Hello, 1) chroot I don't understand how to specify to the php engine to chroot upon different scripts being executed (scripts that i don't control). Would you please clarify? 2)perms The php engine is what has access to specific dirs (not users, scripts,). That i know of, the php engine doesn't allow per user permissions. That is, it is one engine, one set of perms. Are you suggesting i have a separate php engine for each user? 3) Maybe i can simplify this question: How does a hosting company, in a shared virtual host server environment, prevent all their clients (php programmers) from snooping into all the other clients' folders? I am assuming we are all using the same php engine, as it is a shared apache host. O.K. I read and typed too fast. In short, suexec with apache will run a user's scripts as that user so long as php is run as cgi and not the apache mod. Also, virtual hosts in apache define the docroot for a virtual host (user/domain/etc.), so other virtual hosts can't access outside of that docroot into other virtual hosts. So the perms part of my previous reply was related to suexec and chroot was out of my ass because many times you would chroot apache for extra security from the webserver in general. thx for the reply shawn.
[PHP] Frameworks / obstinate?
Tony Marston wrote: "Nitsan Bin-Nun" wrote in message news:d47da0100903220910q7bb66706s6255f0fc89b98...@mail.gmail.com... Don't forget to attach the message to the list. Regarding the frameworks, which of them, for your opinion, will take the fastest time to learn and get into code? Generally speaking if something is fast to learn it is also the first to run out of steam. If it doesn't have more features than you can learn in five minutes the it doesn't have enough features to do anything useful, or with any degree of flexibility. Hello, I changed the subject because I did not want to steal Nitsan's thread. There seem to be a ton of frameworks, one-click installation web applications, the latest and greatest wiz-bang applications out there. I find myself extremely reluctant to dig into these code sets. It seems when I do attempt to use one of these pre-coded applications I end up eventually wanting to modify the code outside of the original extent of the project. Invariably I get frustrated and end up wishing I initially begun the development from scratch. Employers seem to be wanting me to have experience with all kinds of 'gimicky' solutions, but I am reluctant to be constantly learning new applications (that i'd prefer to rewrite myself). Am I just being hard headed and reluctant to change, or is my stance justified? I suppose the answer is the middle-path. That is, read some new projects, take the bits I like, leave the bits I don't, etc...The problem is this isn't very marketable. But I suppose, the proof is in the pudding. What a banal way to end an email, eh? What are your thoughts in regard to these two forces: wiz-bang frameworks vs. raw php development? thanks,
Re: [PHP] Frameworks / obstinate?
Marc Christopher Hall wrote: My personal take on this goes something like this: I'm not a huge fan of re-inventing the wheel. However, it seems that since the first stable release of PHP 5 into the wild a much needed emphasis has been placed on OOP solutions within the PHP world. Don't read me wrong, I know the importance wasn't lost on folks who already had a good programming head on their shoulders, yet, in all fairness our hands were a bit tied (and I feel that I may receive some argument here) until PHP 5 reached its first stable release. That being said, I find that quite a few of the frameworks still seem to be fledglings and a lot of the new OS projects being built on them are like wheels with some lumps. Even a few commercial projects seem to be like this. I also have a positive outlook with PHP5 and 6 and that is that this language is finally reaching maturity. It is something that I believe and hope allow for continued growth of our new projects without feeling the need to dump them like I saw with the PHP4 projects. On a final rambling note, I like some of the new frameworks I've looked into recently, like CodeIgniter, Yii even Sapphire holds some promise (have a look at the cleaner version in progress). I find myself wanting to add to them, wanting to help improve them and occasionally I too have a fleeting moment where I think "How would my framework be different if I built one from scratch?" Then I realize I don't have that kind of time! lol My clients are waiting. Also, I don't seem to have much trouble switching between frameworks or languages for that matter (PERL, PHP, ASP(bleh), JavaScript, ActionScript) and I guess because of that I find myself just trying to find the best solution for the clients need at hand and build from there. -Original Message- From: Daniel Kolbo [mailto:kolb0...@umn.edu] Sent: Sunday, March 22, 2009 4:54 PM To: php-general@lists.php.net Cc: Tony Marston Subject: [PHP] Frameworks / obstinate? Tony Marston wrote: "Nitsan Bin-Nun" wrote in message news:d47da0100903220910q7bb66706s6255f0fc89b98...@mail.gmail.com... Don't forget to attach the message to the list. Regarding the frameworks, which of them, for your opinion, will take the fastest time to learn and get into code? Generally speaking if something is fast to learn it is also the first to run out of steam. If it doesn't have more features than you can learn in five minutes the it doesn't have enough features to do anything useful, or with any degree of flexibility. Hello, I changed the subject because I did not want to steal Nitsan's thread. There seem to be a ton of frameworks, one-click installation web applications, the latest and greatest wiz-bang applications out there. I find myself extremely reluctant to dig into these code sets. It seems when I do attempt to use one of these pre-coded applications I end up eventually wanting to modify the code outside of the original extent of the project. Invariably I get frustrated and end up wishing I initially begun the development from scratch. Employers seem to be wanting me to have experience with all kinds of 'gimicky' solutions, but I am reluctant to be constantly learning new applications (that i'd prefer to rewrite myself). Am I just being hard headed and reluctant to change, or is my stance justified? I suppose the answer is the middle-path. That is, read some new projects, take the bits I like, leave the bits I don't, etc...The problem is this isn't very marketable. But I suppose, the proof is in the pudding. What a banal way to end an email, eh? What are your thoughts in regard to these two forces: wiz-bang frameworks vs. raw php development? thanks, __ Information from ESET Smart Security, version of virus signature database 3953 (20090321) __ The message was checked by ESET Smart Security. http://www.eset.com __ Information from ESET Smart Security, version of virus signature database 3953 (20090321) __ The message was checked by ESET Smart Security. http://www.eset.com Marc, Thanks for the thoughts. [quote]I find myself just trying to find the best solution for the clients need at hand and build from there.[/quote] Certainly the above is the mainstream/business approach. After all, they (businesses) need solutions today and not tomorrow. However, this is the culture that only serves to exemplify my point. All of these one-click-solutions are for today, who is looking out for tomorrow? Who is doing the long term planning? Instead of our snake oil salesmen, who is selling long term stability/flexibility. Is it even possible to make money when thinking about the long term. Is there money for the conservative visionary or is it only for the radical lose cannon. I guess I reall
[PHP] include file in a class with global/parent scope?
Hello, I understand the why $vars is not in the global scope, but i was wondering if there was a way from within the class file to include a file in the parent's scope? i tried ::include('vars.php'), parent::include('vars.php'), but this breaks syntax... Please consider the following three files: 'scope.class.inc' 'vars.php' 'scope.php' cinclude('vars.php'); echo "In original $vars\n";//$vars is not defined*** ?> Thanks, dK -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] include file in a class with global/parent scope?
Martin Scotta wrote: > Where is $vars? there is no $vars in your code... > > You can extract all the global space in the CScope method, it's quite > simple, but less performant. > > > class CScope { > >public $vars = 'class scope\n'; > >function cinclude($filename) { >extract( $GLOBALS ); >include('vars.php'); >echo "In class $vars\n"; >} > } > > On Sun, Jun 14, 2009 at 1:41 PM, Daniel Kolbo <mailto:kolb0...@umn.edu>> wrote: > > Hello, > > I understand the why $vars is not in the global scope, but i was > wondering if there was a way from within the class file to include a > file in the parent's scope? > > i tried ::include('vars.php'), parent::include('vars.php'), but this > breaks syntax... > > Please consider the following three files: > > 'scope.class.inc' > class CScope { > >public $vars = 'class scope\n'; > >function cinclude($filename) { >include('vars.php'); >echo "In class $vars\n"; >} > } > ?> > > 'vars.php' > //global $vars;//if this line is uncommented then the desired result is > achieved however, i don't want to change all the variables to global > scope (this file is includeded in other files where global scoped > variables is not desireable). > $vars = 'vars.php scope\n'; > ?> > > 'scope.php' > include('scope.class.inc'); > $object = new CScope; > $object->cinclude('vars.php'); > echo "In original $vars\n";//$vars is not defined*** > ?> > > Thanks, > dK > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > -- > Martin Scotta replace all $var with $vars. The extract method proposed is the opposite of what i'm looking to do. I want to bring the class's include scope into the calling object's scope. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] include file in a class with global/parent scope?
Hello, I've cleaned up my question a bit. I want the included file which is called within a method of a class to have the same scope as the instantiation of the class's object. That is, i want a class to include a file in the calling object's scope. How would one do this? 'test.php' cinclude(); echo $vars;//i want this to print 'hi' include('vars.php'); echo "obvious $vars"; ?> 'vars.php' OUTPUT: Notice: Undefined variable: vars in ...\test.php on line 10 obvious hi DESIRED OUTPUT: hi obvious hi Thanks, dK -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] mysql_query blocking
Hello, When a MySQL table is locked a php call of mysql_query() that requires that table will hang as the request blocks at the MySQL server until the table is unlocked. Is there a way to stop a mysql_query from hanging (by setting a time limit)? The php.ini directive max_execution_time does not help b/c: "Note: The set_time_limit() function and the configuration directive max_execution_time only affect the execution time of the script itself. Any time spent on activity that happens outside the execution of the script such as system calls using system(), stream operations, database queries, etc. is not included when determining the maximum time that the script has been running." The my.ini directive table_lock_wait_timeout does not work either b/c from MySQL: "This variable currently is unused. " (I am using mysql v5.1) I do not want to bluntly stop this from the apache level. How does one place a time limit on the execution of mysql_query()? Thanks for your help, dK -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mysql_query blocking
Daniel Kolbo wrote: > Hello, > > When a MySQL table is locked a php call of mysql_query() that requires > that table will hang as the request blocks at the MySQL server until the > table is unlocked. Is there a way to stop a mysql_query from hanging > (by setting a time limit)? > > The php.ini directive max_execution_time does not help b/c: > "Note: The set_time_limit() function and the configuration directive > max_execution_time only affect the execution time of the script itself. > Any time spent on activity that happens outside the execution of the > script such as system calls using system(), stream operations, database > queries, etc. is not included when determining the maximum time that the > script has been running." > > The my.ini directive table_lock_wait_timeout does not work either b/c > from MySQL: > "This variable currently is unused. " > (I am using mysql v5.1) > > I do not want to bluntly stop this from the apache level. > > How does one place a time limit on the execution of mysql_query()? > > Thanks for your help, > dK > > Even the apache TimeOut directive does not seem to work in this situation. Any help would be appreciated. Thanks, dK -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mysql_query blocking
Ashley Sheridan wrote: > On Sat, 2009-06-27 at 15:15 -0400, Daniel Kolbo wrote: >> Hello, >> >> When a MySQL table is locked a php call of mysql_query() that requires >> that table will hang as the request blocks at the MySQL server until the >> table is unlocked. Is there a way to stop a mysql_query from hanging >> (by setting a time limit)? >> >> The php.ini directive max_execution_time does not help b/c: >> "Note: The set_time_limit() function and the configuration directive >> max_execution_time only affect the execution time of the script itself. >> Any time spent on activity that happens outside the execution of the >> script such as system calls using system(), stream operations, database >> queries, etc. is not included when determining the maximum time that the >> script has been running." >> >> The my.ini directive table_lock_wait_timeout does not work either b/c >> from MySQL: >> "This variable currently is unused. " >> (I am using mysql v5.1) >> >> I do not want to bluntly stop this from the apache level. >> >> How does one place a time limit on the execution of mysql_query()? >> >> Thanks for your help, >> dK >> >> > It depends on what type of table you have, MyISAM blocks at table level > for instance, while InnoDB locks at row level. > > Thanks > Ash > www.ashleysheridan.co.uk > > I'm using InnoDB. But either way how do you place a time limit on mysql_query()? Thanks, dK -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mysql_query blocking
Ashley Sheridan wrote: > On Sat, 2009-06-27 at 16:03 -0400, Daniel Kolbo wrote: >> Ashley Sheridan wrote: >>> On Sat, 2009-06-27 at 15:15 -0400, Daniel Kolbo wrote: >>>> Hello, >>>> >>>> When a MySQL table is locked a php call of mysql_query() that requires >>>> that table will hang as the request blocks at the MySQL server until the >>>> table is unlocked. Is there a way to stop a mysql_query from hanging >>>> (by setting a time limit)? >>>> >>>> The php.ini directive max_execution_time does not help b/c: >>>> "Note: The set_time_limit() function and the configuration directive >>>> max_execution_time only affect the execution time of the script itself. >>>> Any time spent on activity that happens outside the execution of the >>>> script such as system calls using system(), stream operations, database >>>> queries, etc. is not included when determining the maximum time that the >>>> script has been running." >>>> >>>> The my.ini directive table_lock_wait_timeout does not work either b/c >>>> from MySQL: >>>> "This variable currently is unused. " >>>> (I am using mysql v5.1) >>>> >>>> I do not want to bluntly stop this from the apache level. >>>> >>>> How does one place a time limit on the execution of mysql_query()? >>>> >>>> Thanks for your help, >>>> dK >>>> >>>> >>> It depends on what type of table you have, MyISAM blocks at table level >>> for instance, while InnoDB locks at row level. >>> >>> Thanks >>> Ash >>> www.ashleysheridan.co.uk >>> >>> >> I'm using InnoDB. >> But either way how do you place a time limit on mysql_query()? >> Thanks, >> dK >> > I've not seen this done before, but it should only be row locking if > you're using InnoDB. What queries are you running that are affecting a > script that badly? > > Thanks > Ash > www.ashleysheridan.co.uk > > I issue a 'lock tables tablename write' and do some work. This is to be expected. I want a way that to stop mysql_query() from just waiting for the mysql server. ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mysql_query blocking
Tom Worster wrote: > On 6/27/09 3:15 PM, "Daniel Kolbo" wrote: > >> When a MySQL table is locked a php call of mysql_query() that requires >> that table will hang as the request blocks at the MySQL server until the >> table is unlocked. Is there a way to stop a mysql_query from hanging >> (by setting a time limit)? > > would it be possible to test for presence of the lock before issuing the > query that would block? if so, you could check the lock periodically until > your time limit is up. would achieve you you're looking for? > > > it would still be possible that after checking but before issuing the query the table's could be locked - albeit a much smaller chance. Thanks for the input, dK -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mysql_query blocking
Bastien Koert wrote: > Why issue/do a lock at all? Shouldn't need a large lock at read > > bastien > > On Saturday, June 27, 2009, Daniel Kolbo wrote: >> Ashley Sheridan wrote: >>> On Sat, 2009-06-27 at 16:03 -0400, Daniel Kolbo wrote: >>>> Ashley Sheridan wrote: >>>>> On Sat, 2009-06-27 at 15:15 -0400, Daniel Kolbo wrote: >>>>>> Hello, >>>>>> >>>>>> When a MySQL table is locked a php call of mysql_query() that requires >>>>>> that table will hang as the request blocks at the MySQL server until the >>>>>> table is unlocked. Is there a way to stop a mysql_query from hanging >>>>>> (by setting a time limit)? >>>>>> >>>>>> The php.ini directive max_execution_time does not help b/c: >>>>>> "Note: The set_time_limit() function and the configuration directive >>>>>> max_execution_time only affect the execution time of the script itself. >>>>>> Any time spent on activity that happens outside the execution of the >>>>>> script such as system calls using system(), stream operations, database >>>>>> queries, etc. is not included when determining the maximum time that the >>>>>> script has been running." >>>>>> >>>>>> The my.ini directive table_lock_wait_timeout does not work either b/c >>>>>> from MySQL: >>>>>> "This variable currently is unused. " >>>>>> (I am using mysql v5.1) >>>>>> >>>>>> I do not want to bluntly stop this from the apache level. >>>>>> >>>>>> How does one place a time limit on the execution of mysql_query()? >>>>>> >>>>>> Thanks for your help, >>>>>> dK >>>>>> >>>>>> >>>>> It depends on what type of table you have, MyISAM blocks at table level >>>>> for instance, while InnoDB locks at row level. >>>>> >>>>> Thanks >>>>> Ash >>>>> www.ashleysheridan.co.uk <http://www.ashleysheridan.co.uk> >>>>> >>>>> >>>> I'm using InnoDB. >>>> But either way how do you place a time limit on mysql_query()? >>>> Thanks, >>>> dK >>>> >>> I've not seen this done before, but it should only be row locking if >>> you're using InnoDB. What queries are you running that are affecting a >>> script that badly? >>> >>> Thanks >>> Ash >>> www.ashleysheridan.co.uk <http://www.ashleysheridan.co.uk> >>> >>> >> I issue a 'lock tables tablename write' and do some work. This is to be >> expected. I want a way that to stop mysql_query() from just waiting for >> the mysql server. >> ` >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> > a different user (user who is updating) would be doing the lock. thanks, dK -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mysql_query blocking
Phpster wrote: > > > Bastien > > Sent from my iPod > > On Jun 27, 2009, at 4:13 PM, Daniel Kolbo wrote: > >> Ashley Sheridan wrote: >>> On Sat, 2009-06-27 at 16:03 -0400, Daniel Kolbo wrote: >>>> Ashley Sheridan wrote: >>>>> On Sat, 2009-06-27 at 15:15 -0400, Daniel Kolbo wrote: >>>>>> Hello, >>>>>> >>>>>> When a MySQL table is locked a php call of mysql_query() that >>>>>> requires >>>>>> that table will hang as the request blocks at the MySQL server >>>>>> until the >>>>>> table is unlocked. Is there a way to stop a mysql_query from hanging >>>>>> (by setting a time limit)? >>>>>> >>>>>> The php.ini directive max_execution_time does not help b/c: >>>>>> "Note: The set_time_limit() function and the configuration directive >>>>>> max_execution_time only affect the execution time of the script >>>>>> itself. >>>>>> Any time spent on activity that happens outside the execution of the >>>>>> script such as system calls using system(), stream operations, >>>>>> database >>>>>> queries, etc. is not included when determining the maximum time >>>>>> that the >>>>>> script has been running." >>>>>> >>>>>> The my.ini directive table_lock_wait_timeout does not work either b/c >>>>>> from MySQL: >>>>>> "This variable currently is unused. " >>>>>> (I am using mysql v5.1) >>>>>> >>>>>> I do not want to bluntly stop this from the apache level. >>>>>> >>>>>> How does one place a time limit on the execution of mysql_query()? >>>>>> >>>>>> Thanks for your help, >>>>>> dK >>>>>> >>>>>> >>>>> It depends on what type of table you have, MyISAM blocks at table >>>>> level >>>>> for instance, while InnoDB locks at row level. >>>>> >>>>> Thanks >>>>> Ash >>>>> www.ashleysheridan.co.uk >>>>> >>>>> >>>> I'm using InnoDB. >>>> But either way how do you place a time limit on mysql_query()? >>>> Thanks, >>>> dK >>>> >>> I've not seen this done before, but it should only be row locking if >>> you're using InnoDB. What queries are you running that are affecting a >>> script that badly? >>> >>> Thanks >>> Ash >>> www.ashleysheridan.co.uk >>> >>> >> I issue a 'lock tables tablename write' and do some work. This is to be >> expected. I want a way that to stop mysql_query() from just waiting for >> the mysql server. >> ` >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> > > > > Further thought, do you have indexes on the table? > > > Bastien > Yes. The question is not about MySQL efficiency - i'll leave that to the MySQL email group. This question is about putting in place PHP safe guards. Thanks, dK -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Establishing PHP Session From a Different Host
Hello, How does one continue a php session on a different domain (domain B) than the domain (domain A) that started the session? That is, I want to hand-off a session to another domain, but I do not see how to do this as one cannot set a cookie for another domain (for valid reasons). I was thinking I could pass a one-time-access token in the url of domain B, but i'm dissatisfied with this solution as it gets unwieldy if there are a high volume of requests (such as a document server). Otherwise, I would think the user would have to re-identify (enter username/password) themselves on domain B. I am wondering if someone can enlighten me on how to have seemless session integration across multiple domains. I realize that if the domain has a different php engine, then i'd have to manage the session data outside of php's internal session data store (ie...with something like MySQL). Also, the domains are not subdomains of each other. 1) An example where one might want to do this is to establish a document/asset server on domain B to deliver content of different access levels to domain A's page (and also possibly domain C, D, E, etc...). Maybe I could do some server to server work passing the contents of a readfile(), where domain B always trusts requests from domain A. 2) But what about in situations where I literally want to migrate the user's session from one domain and hand it off to another domain, where both domains have access to the same data tables. How does one do this? Maybe I need to do some reading on load balancing to help me understand how state is maintained across several servers, but i was hoping this community might be able to guide/point me in the proper direction. Thanks, dK ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Establishing PHP Session From a Different Host
Daniel Brown wrote: > On Sun, Jul 12, 2009 at 12:37, Daniel Kolbo wrote: >> Hello, >> >> How does one continue a php session on a different domain (domain B) >> than the domain (domain A) that started the session? > > Simple answer: you don't. > > Extended answer: you can, but only if the domains reside on the > same physical host, or in a setup where one domain can read the > physical files of another across hosts. When you store information in > a $_SESSION array, it stores one key (the PHPSESSID value) in a cookie > on the client side, and then stores what is supposed to be a > more-secure version of the cookie - containing all of the stored data > - as a flat file on the server side (usually in /tmp or ~/tmp). As > such, you shouldn't be able to read them from a different domain > unless your host is insecure, in which you won't have to worry only > about this, but also full cross-site-scripting vulnerabilities. Other > options would be "parking" or doing an "addon" domain, or something of > the like. However, this all gets more into operating system and > network security, and HTTP server configurations. > > Combined answer: you can, but you should really re-evaluate your > code and current capabilities before trying to do so. You may even > want to consider setting up a trust relationship with a centralized > database such as MySQL to allow the second domain to READ ONLY from > the first. Check in the database on the first domain to see if a user > is logged in, if they were active within the last x > (seconds|minutes|hours), and from what IP they were logged in. If > things seem to match up, write the $_SESSION variables for login > without prompting the user to re-authenticate manually. > Thanks for the responses. Re: Simple answer I thought of another example. My bank's website. I sign-in and authenticate with "bank.com". Then, i click credit card from bank.com and i'm redirected to "creditcard.com" without me having to reinput user/pass. They clearly do it (granted they have a lot more resources then I do, but i'd still like to know how they are doing it). Re: extended answer Not that i'd be able to do this, but what type of software is required to set up two remote physical hosts that can share files? Can this be accomplished through apache or perhaps plugging in some network app into apache? I don't fully understand how 'parking/addon' domains would accomplish the goal. Would you explain this option a bit more thoroughly please? Re: combined answer The trust relationship idea is what i have to work with. However, i am not using IP addresses for authentication as I was told this could alienate legitimate users and that IPs may be easily masked. Thus, i was thinking about using a one-time-access token passed in the url (essentially the same idea as the password verification links sent to email in-boxes). Once the user enters domain B with the one time access token, compare this token with last activity time via MySQL. Then if all looks okay to set a cookie with the same sesion ID as was established on domain A. As request time on domain A and subsequent request time on domain B are very close together I could require that the IPs stay consistent during that short-lived time frame. Does the above all seem reasonable (though headache prone)? I'm curious to hear your two cents. I am also curious to know how the big boys do this type of thing. Do you have any links, software applications names, or other types of keywords i could use to research about this type of thing? Thanks for your time, dK ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Internal PHP caching methodology
Hello, Call me a dreamer...but I got to ask. Is there any software for helping speed up PHP by utilizing internal PHP caching? I am not talking about the external php cache/header control. Smarty caching doesn't give me the control I need either. I would like to cache to a finer level than page by page, but rather on a module by module basis. Each of my pages contains a subset of modules. The content of these modules changes based upon certain criteria (link, time, session data, but is sometimes static across the site). I would like to be able to cache individual "modules" (preferably based upon frequency and time to generate). I am trying to develop a way to do this, but I have to think a brighter mind has come before me and hopefully arrived at a solution. As always any help/thoughts are much appreciated, except for that one guy's comments (you all know who I am talking) ~ jk ;) Thanks, ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php.net down?
Thijs Lensselink wrote: > Anybody noticed php.net is down? > > It's responding to pings. But no pages load. > > I noticed this -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Internal PHP caching methodology
Eric Butera wrote: > On Thu, Jul 16, 2009 at 5:50 PM, Daniel Kolbo wrote: >> Hello, >> >> Call me a dreamer...but I got to ask. >> >> Is there any software for helping speed up PHP by utilizing internal PHP >> caching? >> >> I am not talking about the external php cache/header control. Smarty >> caching doesn't give me the control I need either. >> >> I would like to cache to a finer level than page by page, but rather on >> a module by module basis. Each of my pages contains a subset of >> modules. The content of these modules changes based upon certain >> criteria (link, time, session data, but is sometimes static across the >> site). I would like to be able to cache individual "modules" >> (preferably based upon frequency and time to generate). >> >> I am trying to develop a way to do this, but I have to think a brighter >> mind has come before me and hopefully arrived at a solution. >> >> As always any help/thoughts are much appreciated, except for that one >> guy's comments (you all know who I am talking) ~ jk ;) >> >> Thanks, >> ` >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> > > Have you actually profiled your code to see where the pain points are > vs saying 'module?' Are you also running an opcode cache? From there > you can use data, block, or full page caching. Finally you can figure > out if you want to store it in flat files or memory. I'd start by > knowing what is actually the slow part using Xdebug and nail a few > down. > > There is no end all solution. Some pages really don't have a lot > going on and are hardly updated so full page is fine. Others might > have something that is hard to generate on a sidebar, so block caching > would be more suitable for that. As previously mentioned, Zend_Cache > is up to the task. There is also a PEAR package called Cache_Lite > which would work to if you're interested in file based caching. > So dreams do come true... Thank you for the wonderful insight. I've been reading about the memcached and Xdebug and Zend_Cache. I've got lots to learn, but it is exactly the type of material i was trying to find. I am not currently running an opcode cache. I may be doing "premature optimization", but i want to design the entire system intelligently from the get go rather than having to rebuild later. you know 'work smarter not harder' Is it possible to run xdebug on a virtual host server on which i do not have shell access? I can modify php.ini via cgi, but I don't know if i'd be able to view the results of xdebug on the machine. Your opinion would be appreciated. Thanks so much, i feel like i've just been shown a whole new world. dK ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Internal PHP caching methodology
Daniel Kolbo wrote: > Eric Butera wrote: >> On Thu, Jul 16, 2009 at 5:50 PM, Daniel Kolbo wrote: >>> Hello, >>> >>> Call me a dreamer...but I got to ask. >>> >>> Is there any software for helping speed up PHP by utilizing internal PHP >>> caching? >>> >>> I am not talking about the external php cache/header control. Smarty >>> caching doesn't give me the control I need either. >>> >>> I would like to cache to a finer level than page by page, but rather on >>> a module by module basis. Each of my pages contains a subset of >>> modules. The content of these modules changes based upon certain >>> criteria (link, time, session data, but is sometimes static across the >>> site). I would like to be able to cache individual "modules" >>> (preferably based upon frequency and time to generate). >>> >>> I am trying to develop a way to do this, but I have to think a brighter >>> mind has come before me and hopefully arrived at a solution. >>> >>> As always any help/thoughts are much appreciated, except for that one >>> guy's comments (you all know who I am talking) ~ jk ;) >>> >>> Thanks, >>> ` >>> >>> -- >>> PHP General Mailing List (http://www.php.net/) >>> To unsubscribe, visit: http://www.php.net/unsub.php >>> >>> >> Have you actually profiled your code to see where the pain points are >> vs saying 'module?' Are you also running an opcode cache? From there >> you can use data, block, or full page caching. Finally you can figure >> out if you want to store it in flat files or memory. I'd start by >> knowing what is actually the slow part using Xdebug and nail a few >> down. >> >> There is no end all solution. Some pages really don't have a lot >> going on and are hardly updated so full page is fine. Others might >> have something that is hard to generate on a sidebar, so block caching >> would be more suitable for that. As previously mentioned, Zend_Cache >> is up to the task. There is also a PEAR package called Cache_Lite >> which would work to if you're interested in file based caching. >> > > So dreams do come true... > > Thank you for the wonderful insight. I've been reading about the > memcached and Xdebug and Zend_Cache. I've got lots to learn, but it is > exactly the type of material i was trying to find. > > I am not currently running an opcode cache. I may be doing "premature > optimization", but i want to design the entire system intelligently from > the get go rather than having to rebuild later. you know 'work smarter > not harder' > > Is it possible to run xdebug on a virtual host server on which i do not > have shell access? I can modify php.ini via cgi, but I don't know if > i'd be able to view the results of xdebug on the machine. Your opinion > would be appreciated. > > Thanks so much, i feel like i've just been shown a whole new world. > dK > ` I still have to (fully) rtfm. But i was wondering if the following scenario(s) is(are) possible. -Does memcached store the same data under different keys in the same spot? >From my reading so far, i do not think so. My understanding is that currently memcached goes like as follows: key->key_hash->server->data_value but this approach could conceivably store the same data_value under different keys (thus consuming unneeded memory) What i'd like it to do is the following: key->key_hash->server->data_hash->server->data_value That is, each key has the data_hash as its value. Then one uses this data_hash as the new key which has the data_value as its value. This way the only data that is replicated would be the relatively small data_hash, but the (larger) data itself would not be replicated. This would allow for the user to use different keys to access the same data. This would be needed when seemingly different keys happen to share the same data, but would be too costly to recognize, predict, and accommodate such associations This doubles the number of calls to the server, but could conceivable save a great deal of memory for more cached objects. What would be even slicker is if the programmer could use either approach within the same script. For example, if the programmer new for (almost) certain that a certain key would never have the same data signature as any other key, she could then use the original method and save on the overhead of storing key_hash to data_hashes pairs. Also, I really like the idea behind zend_cache that I can use memcache/d as the backend. That's pretty modular! I have three direct questions: 1) Is the above approach wise or have i violated some basic caching principle? 2) Is the php memcache/memcached class extendable (so that I can implement 1 above)? 3) If 2) is yes, can I use this extendable class as the backend for zend_cache? Thanks, dK ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] prepending concatenating assignment operator
Hello, I know the appending concatenating assignment operator: $str_name = "Foobar"; $str_name .= " Sr"; echo $str_name;//Foobar Sr But is there a shortcut assignment operator for prepending concatenation? $str_name = "Foobar"; //$str_name =. "Mr "; // i know this is not allowed, but is there some shorcut? $str_name = "Mr " . $str_name; echo $str_name;//Mr Foobar Just curious. Thanks, dK ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Question on code profiling
Andrew Ballard wrote: > On Thu, Jul 23, 2009 at 11:31 PM, Andrew Ballard wrote: >> From what I can tell, the numbers I see in WinCacheGrind >> look like they are off by about a factor of 10 pretty >> uniformly. >> >> Andrew >> > > Apparently the difference is indeed WinCacheGrind, as a number of > other people have left comments on the project site that the values it > reports need to be multiplied by 10. Now that I know the numbers are > "right" comes the fun part. :-\ > > Andrew > Is this factor of 10 business only for ZF on Windows IIS or for Linux too? thanks, dK ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] OOP Design Software
Hello, Is there an objected oriented programming software that can help me keep track of my methods and properties of my objects. My memory is not what it used to be, and i'd like to have a quick 'overview' or layout of all the objects I have to work with. Maybe the software would even let make a process flow chart. This would really help my design (and save me time). Thanks, dK ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] OOP Design Software
Caner BULUT wrote: > Hi Daniel, > > You can use Eclipse with plugin PDT or Zend Studio. They can track your > classes and methods. They can remember your methods and classes also they > have code completion abilities. > > Thanks > Caner. > > -Original Message- > From: Daniel Kolbo [mailto:kolb0...@umn.edu] > Sent: 26 July 2009 19:46 > To: PHP General > Subject: [PHP] OOP Design Software > > Hello, > > Is there an objected oriented programming software that can help me keep > track of my methods and properties of my objects. My memory is not what > it used to be, and i'd like to have a quick 'overview' or layout of all > the objects I have to work with. Maybe the software would even let make > a process flow chart. This would really help my design (and save me time). > > Thanks, > dK > ` > Wow. Thanks for the reference. I've been playing with EclipsePDT for about 30-45 minutes. I've been developing strictly off of a text editor (with some syntax coloring but that's it). This Eclipse project looks so big. There'll be a bit of a learning curve with the EclipsePDT but seeing that it was developed in part by Zend and also that smarty.net uses it, i can rest assured that my time learning/implementing eclipse will save me a great deal of time in the long haul. I am glad to see it has integration with xdebug and CVS. I'll have to postpone my weekend coding goals to learn Eclipse and see how to integrate it into my development process. Thanks for the recommendation (and quick too). Thanks, dK ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Expand Variables in String
Hello, Is it possible to force a string to expand variable names after the string has been set and before the variable's been defined without having to do a string replace or preg_replace? for example, "; $var = "Variable Contents"; echo $str.""; $str_expanded = $str;//would like this to expand $var into $str_expanded echo $str_expanded.""; ?> Thanks, dK ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Expand Variables in String
Jonathan Tapicer wrote: > Use eval, like this: > > eval('$str_expanded = "' . str_replace('"', '\\"', $str) . '";'); > > The str_replace is used because you could have a " inside $str and it > would break the string, if you are sure the $str has no " inside you > can omit it. > > Jonathan > > On Wed, Jul 29, 2009 at 5:43 PM, Daniel Kolbo wrote: >> Hello, >> >> Is it possible to force a string to expand variable names after the >> string has been set and before the variable's been defined without >> having to do a string replace or preg_replace? >> >> for example, >> > $str = "some string and some \$var plus other stuff"; >> echo $str.""; >> $var = "Variable Contents"; >> echo $str.""; >> $str_expanded = $str;//would like this to expand $var into $str_expanded >> echo $str_expanded.""; >> ?> >> >> Thanks, >> dK >> ` >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> > nice! This would allow me to have $str loaded with all kinds of variables and not have to do a str_replace with each (assuming the quote business is cool) Why did you have the double \\? > eval('$str_expanded = "' . str_replace('"', '\\"', $str) . '";'); Isn't the following equivalent? eval('$str_expanded = "' . str_replace('"', '\"', $str) . '";'); Thanks, dK ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match too greedy
Jim Lucas wrote: > Ben Dunlap wrote: >> Jim Lucas wrote: I expected 'no match' but get 'match'. >> [8<] >>> cut/paste your code and it works for me. >> Works for me as well. I get 'no match' from PHP 5.1.2, 5.2.6, and 5.2.8. What >> version do you have? > > PHP 5.2.5 with Suhosin-Patch 0.9.6.2 (cli) (built: Mar 11 2008 13:08:50) > Copyright (c) 1997-2007 The PHP Group > Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies > with Suhosin v0.9.20, Copyright (c) 2002-2006, by Hardened-PHP Project > > >> If I might suggest a couple of simplifications that would make it easier to >> follow/troubleshoot: >> $url = '/foo(/)?'; >> I don't think you need parentheses around your second forward-slash. If you >> had >> multiple characters that were optional you'd want to group them in >> parentheses, >> but here I think it just makes the regex harder to read. >> echo (preg_match($pattern, $test) != false) >> The " != false " here is redundant. Combined with the ternary operator, the >> logical switchbacks make me a little dizzy (especially this close to >> lunchtime). >> >> Ben >> > > > code works (no match) for me too on php 5.2.6 build date May 2 2008 18:01:20 with dumbdows NT. preg_match fails but for a reason other than what I think you may be expecting. It fails b/c of the first forwards slash in $url. The regex engine doesn't even get past the second character let alone reaching the end of line anchor. Also, your code works (no match) with this first forward slash removed: $url = 'foo(/)?' This time preg_match fails due to the end of line anchor. hth dK ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match too greedy
b wrote: > On 07/29/2009 07:48 PM, Daniel Kolbo wrote: >> >> code works (no match) for me too on php 5.2.6 build date May 2 2008 >> 18:01:20 with dumbdows NT. >> >> preg_match fails but for a reason other than what I think you may be >> expecting. It fails b/c of the first forwards slash in $url. The regex >> engine doesn't even get past the second character let alone reaching the >> end of line anchor. > > The forward slash shouldn't be an issue as the delimiter is '%'. The > full pattern is: > > %^/foo/?$%U > > >> Also, your code works (no match) with this first forward slash removed: >> $url = 'foo(/)?' > > But the string happens to start with a forward slash. > > i am not talking about the delimiter your pattern is: %^/foo/?$%U your test string is: 'foo/bar' the first character of your pattern is a "/" and your first character of your test string is an "f". They do not match. The regex engine stops after checking the first character. This has nothing to do with greediness or end of line anchors, but only with the first character comparisons. maybe what you wanted for your test string was '/foo/bar' This test string would then require your end of line anchor. Because the end of line character does not match the "b" the engine stops. No match. This is consistent with the findings of others who replied to you. Perhaps your regex engine has a different syntax for anchors. For example if your engine was seeing the carrot as a an exclusion operator rather than being a beginning of line anchor and it was also, idk, ignoring the dollar sign as your end of line anchor then you would get a match. But otherwise I would recommend you copy/paste the example you provided and confirm that you still get a match. Then i would confirm your regex engine's anchor syntax. Then, recompile your software dK ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regex - filtering out chinese utf8 characters
Merlin Morgenstern wrote: > Hi there, > > I am trying to filter out content that is not ascii. Can I do this with > regex? For example: > > $regex = '[AZ][09]'; > if (preg_match($regex, $text)) { > return TRUE; > } > else { > return FALSE; > } > > The reason I need to do this is that I am doing a mysql query with the > text and I need to make sure it is not UTF8. Otherwise I do get > following error: > > Error: Illegal mix of collations (latin1_swedish_ci,IMPLICIT) > and (utf8_general_ci,COERCIBLE) for operation '=' > > I am new to regex and would be happy for a jump start to get this fixed. > > Best regards, Merlin > You prolly have already been here: http://www.regular-expressions.info/ But if not, that site is certainly useful for all things regex. Sorry I can't be of more help for your specific question. dK ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHPGitAdmin Project Brainstorm
Hello, I had a thought today while walking...why do all ideas come while walking under the sun rather than slouching in front of the LCD's glow? Wouldn't it be cool to develop an application that allowed one to manage Git via PHP? I'm thinking, sorta like how the PHPMyAdmin project helps people manage MySQL via PHP. The reach for PHPGitAdmin would prolly not be as great as it is for PHPMyAdmin, b/c most hosting services do not let one run git (executing shell commands), i assume. I'm still new to Git and Subversion, after a few days of research I think I'm more inclined towards Git. I am not exactly sure how the PHPGitAdmin project would work, but I'm thinking aloud right now. Maybe there is such a feature already available. I guess eclipse and the git plug-in effectively accomplish a similar task, but this requires people to have the eclipse framework rather than a browser and the i-net (which everyone hopefully has). What do you all think about this project? Thanks, dK ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] to a css file requires .css ???
Hello, I realize this is more of an html question than a php, but I was hoping someone here would know what's going on. I am linking to a stylesheet and it is requiring me to use *.css extension. I want to use a .php extension (and have the php engine generate css). However, whenever i use a .php extension the link tag does not seem to work. This works! http://localhost:8080/some.css"; /> This doesn't work but I don't understand why not??? http://localhost:8080/some.php"; /> The page http://localhost:8080/some.php displays the css exactly the same as http://localhost:8080/some.css Why can't I link to a css file by using a different extension? Thanks in advance, dK ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] to a css file requires .css ???
Daniel Kolbo wrote: > Hello, > > I realize this is more of an html question than a php, but I was hoping > someone here would know what's going on. > > I am linking to a stylesheet and it is requiring me to use *.css > extension. I want to use a .php extension (and have the php engine > generate css). However, whenever i use a .php extension the link tag > does not seem to work. > > This works! > href="http://localhost:8080/some.css"; /> > > This doesn't work but I don't understand why not??? > href="http://localhost:8080/some.php"; /> > > The page http://localhost:8080/some.php displays the css exactly the > same as http://localhost:8080/some.css > > Why can't I link to a css file by using a different extension? > > Thanks in advance, > dK > ` > Sorry, I am pretty sure i figured out why. I think it has to do with Content-Type header. Thanks, dK ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Two Parser Passes
Hello, Is it possible to get a list (array) of classes not found in a script before the fatal error exits the parser. I realize that PHP parses the script twice. It would be nice at the end of the first parsing pass to check to see which classes haven't been defined (yet), so that I could define them before the second pass. This way I could load only those classes a script needs. Thanks in advance, dK ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Two Parser Passes
Steve wrote: > Daniel Kolbo wrote: >> Hello, >> >> Is it possible to get a list (array) of classes not found in a script >> before the fatal error exits the parser. I realize that PHP parses the >> script twice. It would be nice at the end of the first parsing pass to >> check to see which classes haven't been defined (yet), so that I could >> define them before the second pass. This way I could load only those >> classes a script needs. >> >> Thanks in advance, >> dK >> ` >> > It sounds like you are looking for autoload: > http://www.php.net/manual/language.oop5.autoload.php > Mr. Steve that's pretty cool. Thanks. Is there a similar type function for autoloading undefined functions? Thanks, dK ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Classes and Functions
Hello, Is there a way to see what objects and functions a script loaded/required/used? I could recursively loop through the globals, but if objects were unset, then i may miss some. I could make a 'tracking' object and every time i load/include a file (which contains a class def or a function def) to add that file to the tracking object...but it would be nice if i didn't have to modify my existing code to see which objects and functions a script actually used, or at least, requested and loaded into memory. Thanks in advance, Daniel Kolbo ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHP internal memory
Hello PHP-hipsters, I am not sure how to phrase these questions so please bare with me. I am thinking about performance of a single web server running Apache (non-cluster) with php as a module. I have a web app that requires the same php objects(classes) for each http request. First, I would like to have the web server keep these object/class definition files (code) permanently in the memory so the php engine does not have to keep loading and destroying these objects. Is this possible? Maybe the php engine is already smart enough to handle this. I imagine the engine is smart enough to not load the same class definition into memory for the same http request, but I'm not sure if the engine is smart enough to recognize that a class definition is already in the memory from a different http request. Second, furthermore, say two different http requests actually instantiate identical objects. Will both of these identical objects require their own space in the memory, or is the php engine smart enough to point both objects to the same memory (until something happens to one of the objects making it different than the other)? If not, i guess this is where the idea of caching comes in, and i have to be that smart one to define the unique keys... Third, when one caches php code using something like memcache, what is actually being cached: the human readable php, the parsed php, the serialized php (not really sure what this is), the raw cpu/assembly instructions, etc...? Fourth, where does this cached data live - on the server's hard drive or in the server's memory (assuming we have enough memory)? I assume one of the ideas behind the cache is to by-pass the php parser and instead just regurgitate the pre-chewed food and spit it out to apache. Thus, the memcache would only be storing the php output. Is this line of reasoning correct? And ideally it would be best to have this prechewed code sitting in the memory, but can I control this? Just to be clear, I am familiar with the idea behind setting a unique key for the cache and all that. Also, i am not referring to client side caching. Well thanks for sticking with me, as I'm trying to learn these concepts. Any comments, answers, explanations would be most welcomed. Thanks, DanK ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] OOP Design Question
Hello PHPers, I have a collection of about 60 objects (class definitions). They are all very similar. They all share a substantial % of the same core. But they all have slight variations as well. The approach I took was to make an abstract core class, and each of the 60 objects extends that core. This works, but... Here's my problem, not every php/http request requires all 60 objects. At this point, I do not know in advance which objects will be required, so i include the class def of all 60 objects every time... I don't like this idea as it seems a 'bloated' approach. So now i'm thinking instead i'll just have one object which has the union of all the 60 objects' methods. But i'm not too happy with this either b/c (i) now each instantiated object is carrying around a lot of unneccessary baggage, (ii) i lose modularity of code, and (iii) the code does not make as much 'intuitive' sense. For (iii), 'why does this object have this method?' type questions another programmer would ask (or me a year from now). The answer would be 'efficiency concerns', which i'm aware that you generally don't want to compromise code readability for efficiency if avoidable. Maybe this would be the perfect opportunity for the php autoload functions...? Thanks for your help/thoughts/comments, dK ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] efficiency of include()
Hello PHPers, This is a two part question: 1) Is it faster to include one file with lots of code, or many separate smaller individual files? Assume the one massive file is merely the concatenation of all the smaller individual files. (I am assuming the one massive file would be faster..., but i wanted to get confirmation). 2) Suppose php has to invoke the include function 100 times. Suppose all files are on average the same size and contain the same number of instructions. Would it be faster to include the same exact file 100 times as opposed to 100 different file names? Basically, does the engine/parser take any shortcuts if it notices that the file name has already been included once? I would test this, but i don't want to create hundreds of different files... Thanks, dK ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] efficiency of include()
Larry Garfield wrote: > On Sunday 20 December 2009 10:45:45 am Daniel Kolbo wrote: >> Hello PHPers, >> >> This is a two part question: >> >> 1) Is it faster to include one file with lots of code, or many separate >> smaller individual files? Assume the one massive file is merely the >> concatenation of all the smaller individual files. (I am assuming the >> one massive file would be faster..., but i wanted to get confirmation). > > Conventional wisdom is that the one big file is faster, since it requires one > disk I/O hit instead of several. HOWEVER, if you're only using a small > portion of that code then it could be faster to load only the code you really > need. Where the trade off is varies with your architecture, the amount of > code, ad how good the disk caching of your OS is. > >> 2) Suppose php has to invoke the include function 100 times. Suppose >> all files are on average the same size and contain the same number of >> instructions. Would it be faster to include the same exact file 100 >> times as opposed to 100 different file names? Basically, does the >> engine/parser take any shortcuts if it notices that the file name has >> already been included once? > > I'm pretty sure that PHP will recognize that it's already parsed that file > and > keep the opcode caches in memory, so it needn't hit disk again. I've not > checked into that part of the engine, though, so I may be wrong there. > Thanks for the reply. For 2): I've often searched for php parsing documentation. I love the php.net documentation. However, i have yet to find an excellent source documenting the php parser/engine. My searches always yield the zend website, but it doesn't seem like i can get very far from that page. Any suggestions on where i could learn more of the nitty gritty details of the php/zend behaviours? Thanks, dK ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Multiple Inheritance Concern
Hello PHPers, I've learned that php doesn't support multiple inheritance, b/c if you need multiple inheritance usually it is a sign you've got a design imperfection...or so they say. Well, I'm using a framework (Codeigniter), and i'm extending the core libraries. The trouble is, I want to also extend a second custom class, and I don't want to change the core codeigniter class definitions as this makes for awkward upgrades. I read about mixins - no thank you. i do not want to even think about mixins as it looks like it would be the source of all debug hell... What's a programmer to do? Is the only option i am really left with to duplicate the code in each class? Thanks, dK ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Multiple Inheritance Concern
Daniel Kolbo wrote: > Hello PHPers, > > I've learned that php doesn't support multiple inheritance, b/c if you > need multiple inheritance usually it is a sign you've got a design > imperfection...or so they say. > > Well, I'm using a framework (Codeigniter), and i'm extending the core > libraries. The trouble is, I want to also extend a second custom class, > and I don't want to change the core codeigniter class definitions as > this makes for awkward upgrades. > > I read about mixins - no thank you. i do not want to even think about > mixins as it looks like it would be the source of all debug hell... > > What's a programmer to do? Is the only option i am really left with to > duplicate the code in each class? > > Thanks, > dK > ` I just found this in the archive: http://old.nabble.com/Multiple-Inheritance-td15717829.html That example Nathan provides of mixin is a lot cleaner than a different example (from a different poster on a different site) i was looking at. I could probably use the method Nathan proposed in a pretty clean way. i'm justified for using this multiple inheritance workaround to keep the core framework untouched? Does anyone else have a different approach or suggestion? Thanks, dK ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Multiple Inheritance Concern
Larry Garfield wrote: > On Friday 25 December 2009 8:02:06 pm Daniel Kolbo wrote: >> Hello PHPers, >> >> I've learned that php doesn't support multiple inheritance, b/c if you >> need multiple inheritance usually it is a sign you've got a design >> imperfection...or so they say. >> >> Well, I'm using a framework (Codeigniter), and i'm extending the core >> libraries. The trouble is, I want to also extend a second custom class, >> and I don't want to change the core codeigniter class definitions as >> this makes for awkward upgrades. >> >> I read about mixins - no thank you. i do not want to even think about >> mixins as it looks like it would be the source of all debug hell... >> >> What's a programmer to do? Is the only option i am really left with to >> duplicate the code in each class? >> >> Thanks, >> dK >> ` > > If the original author of one or both libraries did their job right, they'll > have provided an interface as well as the class that implements it. Then you > can implement the interface and pass through to a new instance using > composition. > > To wit: > > interface AInterface { > public function doA(); > } > > interface BInterface { > public function doB(); > } > > class A implements AInterface { > public function doA() { ... } > } > > class B implements BInterface { > public function doB() { ... } > } > > class YourClass extends A implements BInterface { > > protected $b; > > public function __construct() { > $this->b = new B(); > } > > public function doB() { > return $this->b->doB(); > } > } > > (It would probably be a little more complicated in a real use case, but > hopefully that should get you the idea.) > > Mind you, that presumes that the code you're dealing with provides interfaces > and when doing type checking checks against the interfaces rather than the > classes themselves. If they don't, you should file a bug against that base > library as They're Doing It Wrong(tm). > Yes, I understand. Thanks for taking the time to write up the example. Thanks, dK ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Noob stuff - Zend/Opcode/Cache/Optimizer
Hello, I'm missing some unifying piece of the zend/php puzzle... I understand the basics of zend engine opcode, caching the opcode, optimizing the opcode, and caching the optimized opcode, etc... The part I'm struggling with is somewhere in the zend world. Under a typical php install where does the zend engine live (like what file)? I am under the impression that I need to install the Zend Server Community Edition (ZSCE) to get the zend optimizer+. I thought PHP came with the zend engine...why do i now have to download this ZSCE just to add a component to the engine i already have? 1) Is there a way to turn on zend optimizer+ component (like in php.ini zend extension) without having to install ZSCE? 1.2) If i have to install the ZSCE stack, wouldn't this effectively be adding another engine on my machine? 2) Does zend optimzer+ automatically cache the script's optimized opcode? 3) Is it possible to have APC cache the zend optimzer+ optimized opcode? 4) When APC automatically caches script's opcode is it doing this on 'per included file' basis or on the entire root script (like after the root file has finished including all of its includes)? 5) Same as 4) but for zend optimizer+ instead of APC. Thanks for helping me get a handle on this, dK ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Noob stuff - Zend/Opcode/Cache/Optimizer
Shawn McKenzie wrote: > Daniel Kolbo wrote: >> Hello, >> >> I'm missing some unifying piece of the zend/php puzzle... >> >> I understand the basics of zend engine opcode, caching the opcode, >> optimizing the opcode, and caching the optimized opcode, etc... The >> part I'm struggling with is somewhere in the zend world. >> >> Under a typical php install where does the zend engine live (like what >> file)? > > I don't think it is separate from PHP itself. The Zend engine was a > rewrite of the PHP execution engine with resource/mem management and the > API for loadable extensions, etc... Later adding the PHP 5 OOP stuff. > >> I am under the impression that I need to install the Zend Server >> Community Edition (ZSCE) to get the zend optimizer+. I thought PHP came >> with the zend engine...why do i now have to download this ZSCE just to >> add a component to the engine i already have? >> >> 1) Is there a way to turn on zend optimizer+ component (like in php.ini >> zend extension) without having to install ZSCE? > > It is an extension available on the Zend download page. > >> 1.2) If i have to install the ZSCE stack, wouldn't this effectively be >> adding another engine on my machine? > > Yes, it is a install of PHP with alot of other stuff bundled in. So it > depends upon what you need and if you want to install/configure PHP > yourself with all of these additions, or if you just want to install the > Zend server. > > Hello Mr. McKenzie, Thanks for the response. I do not see zend optimizer+ on: http://www.zend.com/en/downloads/ There is a zend optimizer download link, but this is different than zend optimizer+. My understanding is the former facilitates with the use of zend gaurd while the latter optimizes the opcode. I want the latter component. Where does one obtain the zend optimizer+ component? (I spent the better part of my saturday trying to find it). I ended up installing the zend server community edition to see how it configured its own apache and php installs in the httpd.conf and php.ini as a way to shed some light on to my understanding. The zend server is using different libraries then the standard php install. I could try to mimic the behaviour of the zend server configuration with my original php configuration; however, I'm a bit concerned about only grabbing partial components...maybe i don't need to be so worried. Maybe this plan isn't even possible. I guess i was expecting to google, 'install zend optimizer+ component' and find gogles of howtos. Because i don't see this, it makes me wonder if i'm trying to do something i oughta not... My question boils down to: How do I extend my current php install to add a component (zend optimizer+) to my current php install? Thanks, dK ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Classes and Functions
Nathan Rixham wrote: > Daniel Kolbo wrote: >> Hello, >> >> Is there a way to see what objects and functions a script >> loaded/required/used? >> >> I could recursively loop through the globals, but if objects were unset, >> then i may miss some. >> >> I could make a 'tracking' object and every time i load/include a file >> (which contains a class def or a function def) to add that file to the >> tracking object...but it would be nice if i didn't have to modify my >> existing code to see which objects and functions a script actually used, >> or at least, requested and loaded into memory. >> >> Thanks in advance, >> Daniel Kolbo >> ` >> > > if it's for debugging, get a good debugger so you can inspect at break > points; for use during runtime and something "scripted" you can call the > relevant get_defined/declared functions before before your app does it's > loading, then the same later on and compare to get a definitive list. > > also worth asking if you're refering to objects (as in instances) or > classes. > > Object = instance of a Class [ $object = new Class() ] > Hello Mr. Rixham, Thanks for the reminder about those 'get' functions. (just what i was looking for). Thanks, dK ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Multiple Inheritance Needed in OOP?
Hello, Okay so PHP designers explicitly decided against multiple inheritances, but aren't there legitimate needs for multiple inheritance in OOP? For example, consider the following three classes (A,B,C) with the following properties (a number is a distinct property or method). A: 1, 2, 3 B: 1,3 C: 1, 2, I would like to set the 3 classes up so that no object has 'extra' properties than it requires, so that no property has to be declared/defined in two or more classes, and so that we are strictly using single inhertiance. I don't think it's possible. I've been incorrect beforee...If i'm incorrect please let me know how to set this up as a single inhertance class structure. If this is not possible, why doesn't the PHP community implement multiple inheritance? (I'm anticipating that someone will say, you simply need to redefine what you are calling your objects so that the properties do permit a single inheritance...) I'm very interested to hear why there is the dogma of single inheritance only. Thanks, dK ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Multiple Inheritance Needed in OOP?
Larry Garfield wrote: > On Monday 28 December 2009 9:45:03 pm Daniel Kolbo wrote: >> Hello, >> >> Okay so PHP designers explicitly decided against multiple inheritances, >> but aren't there legitimate needs for multiple inheritance in OOP? >> >> For example, consider the following three classes (A,B,C) with the >> following properties (a number is a distinct property or method). >> >> A: 1, 2, 3 >> B: 1,3 >> C: 1, 2, >> >> I would like to set the 3 classes up so that no object has 'extra' >> properties than it requires, so that no property has to be >> declared/defined in two or more classes, and so that we are strictly >> using single inhertiance. I don't think it's possible. I've been >> incorrect beforee...If i'm incorrect please let me know how to set this >> up as a single inhertance class structure. >> >> If this is not possible, why doesn't the PHP community implement >> multiple inheritance? (I'm anticipating that someone will say, you >> simply need to redefine what you are calling your objects so that the >> properties do permit a single inheritance...) >> >> I'm very interested to hear why there is the dogma of single inheritance >> only. >> >> Thanks, >> dK >> ` > > Because pure multiple inheritance can lead to all sorts of highly weird > behavior when you don't know which parent class you mean at any given time. > Single inheritance is just easier to wrap your head around, and wrap the > compiler's head around. > > What you're looking for is composition, which can do pretty much what you're > looking for. See my last reply to you on this list from Christmas day. > > There's been some discussion of implementing "traits" in later versions of > PHP, but no concrete patches so far. > Hello Mr. Garfield, I saw your reply on how to mimic composition, and I appreciate your comments. I don't prefer (not saying that anyone really does) the mixin approach as private/protected aspects of the mixined class are not available in the pseudo-child class. Also, the code may still need to be maintained in the child class for some changes in the parent class. I would prefer to throw too much into my parent class then to deal with the mixin approach (at this time). I understand about a seemingly simple idea, being not so simple to implement. However ;), for name conflict issues, the compiler could have a simple rule. Such a proposed rule might be for the compiler to throw a warning and to use the last definition supplied. This way multiple inheritance is available for those that legitimately need it and the warning is there so the 'spooky' behaviour scenario can be isolated to an hesitance name conflict. I was reading the request for comments about the traits. My thought is, if we go through the work of allowing horizontal reuse into php, why not do the work for multiple inheritance first. I could understand having the default install to only single inheritance, but i do not understand why php programmers are not, at least, given the option. Thanks, dK ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Multiple Inheritance Needed in OOP?
Daniel Egeberg wrote: > On Wed, Dec 30, 2009 at 01:24, Daniel Kolbo wrote: >> This way multiple inheritance is available for those that legitimately need >> it [...] > > Could you by any chance provide an example where multiple inheritance > would be required? To be honest, I've never really seen a use for it, > but that may be because I've not used a language that supports > multiple inheritance (not on classes anyway). > In the OP i had an example: >> For example, consider the following three classes (A,B,C) with the >> following properties (a number is a distinct property or method). >> >> A: 1, 2, 3 >> B: 1,3 >> C: 1, 2, >> >> I would like to set the 3 classes up so that no object has 'extra' >> properties than it requires, so that no property has to be >> declared/defined in two or more classes, and so that we are strictly >> using single inheritance. Granted this example has the additional specifications of not having inherited extra properties then needed and not having duplicated code. This example doesn't 'require', multiple inheritance, as we could always just throw all of our code (methods, properties) we would ever possibly conceive of needing into one root class and have all classes extend the root class. So no, there is no example where it would be absolutely required, but i argue the above example legitimates the need for multiple inheritance. Other reasons: If the only way to make your classes follow strict single inheritance is to reduce readability and/or confuse the intuitive understanding of the design's class model structure, then i would argue readable and intuitive code is a legitimate reason (perhaps even a requirement ;) Also, if one is trying to enhance a 3rd party's code, but the 3rd party didn't provide access to the code (closed source) and/or they didn't provide interfaces to allow for mixins. Also, if you don't want to deal with the headache and drawbacks of mixins. Also, if you want to ensure higher levels of code maintainability and so don't want to duplicate code. Also, if you are concerned about your code's efficiency and want to avoid the situation of throwing in all the methods higher up the parent class chain. I think that this list of reasons (specifically maintainability, readability, and efficiency) more than justifies the concern of resolving namespace conflicts. Thanks, dK ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: PHP programming strategy; lots of little include files, or a few big ones?
Daevid Vincent wrote: > > >> -Original Message- >> From: Al [mailto:n...@ridersite.org] >> Sent: Wednesday, January 06, 2010 5:09 PM >> To: php-general@lists.php.net >> Subject: [PHP] Re: PHP programming strategy; lots of little >> include files, or a few big ones? >> >> >> >> On 1/6/2010 7:18 PM, clanc...@cybec.com.au wrote: >>> I have a flexible program, which can do many different >> things according to the type of >>> data it is fed. Ideally the flexibility is achieved by >> calling different functions, >>> though when the functionality is ill-defined I sometimes >> just include blocks of code. >>> Ideally, from the point of program maintenance, each module >> should not be too long -- >>> preferably just a page or so. This doesn't raise problems >> in a compiled language, but in >>> an interpreted language like PHP the programmer must decide >> whether to lump a whole lot of >>> functions into a single large include file, or to include >> lots of little files as the >>> particular functions are needed. >>> >>> The first case can lead to memory bloat, as there are >> likely to be a lot of unused >>> functions in memory on any given pass, whereas the second >> case may require lots of little >>> files to be loaded. >>> >>> Are there likely to be significant performance costs for >> either approach, and what are >>> your feelings about the relative virtues of the two approaches? > > I think it's a case by case basis. Generally File I/O is expensive, but > then again, as you say, having everything in a couple files is also > sub-optimal for organizing and keeping things modular. > > I suggest you go with smaller files that are organized into logical > 'chunks'. For example, functions that are used frequently are grouped into > a common.inc.php rather than by topic (such as file/date/xml/forms/etc). > And then use topical includes for the rest. > > More importantly, I suggest you get a good caching system like memecached > or any of the others out there. Then you can pre-compile and load these > files and the whole point becomes close to moot. > > ÐÆ5ÏÐ > http://daevid.com > > "Some people, when confronted with a problem, think 'I know, I'll use > XML.'" > Now they have two problems. > > I had a similar issue but with classes (not functions). I opted to keep my classes short and succinct, rather than shoving all the method functionality into one all-purpose class. Instead of blindly loading all the little classes on each http request, I used (and was recommended on this list to use) __autoload(). The script would only load my classes if the individual request needed it. This helped to avoid the memory bloat. I've heard magic functions like __autoload are a bit slower, but the code is so much cleaner b/c of it. Also, an opcode cache as suggested previously would facilitate the rapid include of many small files. Unfortunately, php does not offer an __autoload() type function to autoload functions. If you are able to encapsulate your functions functionality into classes you may be able to use the above solution of using an opcode cache to help __autoload() a bunch of small classes. hth, dK ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] OO Design Formally
Hello PHPers, I've been doing the programming thing for about 10 years now: amateur side gigs turned into ten years pretty fast. I think i have a fairly strong sense of object oriented design, data modeling, etc... However, sometimes I wish I had a stronger academic understanding of the design / planning phase of new systems. Then I could be absolutely certain my design is correct before investing mega $ and time into the implementation phase. I think I'd save myself a lot of time and frustration if I could improve my designs before I started coding...obvious right? Well, i've read the wikis, the forums, the blogs, etc... I think i need a text book. I'm looking for an OO design methodology recommendations which focuses on churning out reuseable / flexible deliverables. I'm not afraid of getting all academic about it either. It is about time I really got down into the nitty gritty of "proper" OO design methods. I'd appreciate any recommendations as for improving my OO design approach/methodology. Thanks, dK ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] __call and recursion
Hello, I've defined a __call() method inside a class. Within the __call() method (after testing that the method exists and is callable I am using: call_user_func_array(array($this,$method), $args); However, this seems to be an infinite loop (and is crashing my test apache server). How, could I still use the __call() method and avoid an infinite loop of calling? Thanks, dK ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Static Methods and System Resources
Hello, Does PHP 'reinclude' static methods with each new instantiation of a class that has static methods? That is, if i have 100 objects is the static method sitting in memory 1 time or 100 times? Thanks, dK ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Netbeans XDebug Breakpoints Socket Accept
Hello, I'm trying to use the debugging features of Netbeans for the first time. The Netbeans debugger is not stopping at breakpoints. I searched the net, I found out i wasn't the only one with such issues. However, after going through the various posts, etc... i am still without a resolution. Setup: Windows XP Home SP3 PHP Version 5.2.6 XDEBUG Version 2.1.0 Apache Version Apache/2.2.10 (Win32) PHP/5.2.6 Hostname:Port localhost:8080 my php.ini has: zend_extension_ts="c:/php/ext/php_xdebug-2.1.0-5.2-vc6.dll" extension=php_sockets.dll xdebug.var_display_max_depth = 4 xdebug.remote_enable=on xdebug.remote_handler=dbgp xdebug.remote_host=localhost xdebug.remote_port=9000 Some posts said the problem might be with a faulty XDebug install. My phpinfo says: xdebug.remote_port 90009000 xdebug.remote_enableOn On xdebug.remote_host localhost localhost xdebug.remote_handler dbgpdbgp I added port 9000 to my COMODO firewall. I even disabled the firewall, still no success. when i run the following script i receive the php warning: "Warning: socket_accept() [function.socket-accept]: unable to accept incoming connection ..." (if i don't set the socket to nonblock then the script will hang) Also, when i run the following script: I receive 'startstop' with no apparent pause in execution. In netbeans, the play and debug both display to the browser fine, however the debug doesn't stop at break points nor at my cursor (if i tell it to stop at cursor). Why are my breakpoints not stopping? Why can I not accept a socket on port 9000? Any help would be much appreciated. Thanks, ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Netbeans XDebug Breakpoints Socket Accept
tedd wrote: > At 7:04 PM -0400 7/10/10, Daniel Kolbo wrote: >> Hello, >> >> I'm trying to use the debugging features of Netbeans for the first time. >> The Netbeans debugger is not stopping at breakpoints. I searched the >> net, I found out i wasn't the only one with such issues. However, after >> going through the various posts, etc... i am still without a resolution. >> > > Daniel: > > You might try posting your question to the NetBeans list, namely: > > List-Subscribe: <mailto:sy...@php.netbeans.org?subject=subscribe%20users> > > They are pretty good at answering questions. > > Cheers, > > tedd > > Tedd, Thanks for the response. For posterity (should anyone be going through the same headache i went through), I'm replying with a link to the resolution. The issue had to do with a netbean project setting. I posted the resolution to the netbean's forum. http://forums.netbeans.org/viewtopic.php?p=79554 Thanks, dK ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Static Class Member References
Hello PHPers, I'm having some trouble understanding some PHP behaviour. The following example script exhibits the behaviour which I cannot understand. [code] c =& A::$a; } } $c = new C; $b = new B; $cee = new C; var_dump($c->c); // [i] prints object(B), but [ii] prints int 3 var_dump($cee->c); // [i] prints object(B), and [ii] prints object(B) ?> [/code] Why does $c->c print 'int 3' ? I'm nervous to use "self::$a = $this;" because I don't want to be copying the whole object. However, isn't $this just a reference to the object, so "self::$a = $this;" is just copying the reference and not the actual object, right? Thanks in advance ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Static Class Member References
Richard Quadling wrote: > On 11 July 2010 23:19, Daniel Kolbo wrote: >> Hello PHPers, >> >> I'm having some trouble understanding some PHP behaviour. The following >> example script exhibits the behaviour which I cannot understand. >> [code] >> > >> class A >> { >>public static $a = 3; >> >>function __construct() >>{ >>//self::$a = $this; //[i] >>self::$a =& $this; //[ii] >>} >> } >> >> class B extends A >> { >>function __construct() >>{ >>parent::__construct(); >>} >> } >> >> class C { >>var $c; >> >>function __construct() >>{ >>$this->c =& A::$a; >>} >> >> } >> >> >> $c = new C; >> $b = new B; >> $cee = new C; >> >> var_dump($c->c); // [i] prints object(B), but [ii] prints int 3 >> var_dump($cee->c); // [i] prints object(B), and [ii] prints object(B) >> >> ?> >> [/code] >> >> Why does $c->c print 'int 3' ? >> >> I'm nervous to use "self::$a = $this;" because I don't want to be >> copying the whole object. However, isn't $this just a reference to the >> object, so "self::$a = $this;" is just copying the reference and not the >> actual object, right? >> >> Thanks in advance > > > What do you think the value should be? > > A static property is bound to the class and not to an instance of the class. > > So, &A::$a is a reference to the static value. If you alter the value, > it will be altered for a subclasses of A and for any other reference > to it. > I think var_dump($c->c); would print object(B), but it's printing int 3. The reference is *not* being updated. I think this is a bug. What do you think? Thanks ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Static Class Member References
Richard Quadling wrote: > On 12 July 2010 22:54, Daniel Kolbo wrote: >> Richard Quadling wrote: >>> On 11 July 2010 23:19, Daniel Kolbo wrote: >>>> Hello PHPers, >>>> >>>> I'm having some trouble understanding some PHP behaviour. The following >>>> example script exhibits the behaviour which I cannot understand. >>>> [code] >>>> >>> >>>> class A >>>> { >>>>public static $a = 3; >>>> >>>>function __construct() >>>>{ >>>>//self::$a = $this; //[i] >>>>self::$a =& $this; //[ii] >>>>} >>>> } >>>> >>>> class B extends A >>>> { >>>>function __construct() >>>>{ >>>>parent::__construct(); >>>>} >>>> } >>>> >>>> class C { >>>>var $c; >>>> >>>>function __construct() >>>>{ >>>>$this->c =& A::$a; >>>>} >>>> >>>> } >>>> >>>> >>>> $c = new C; >>>> $b = new B; >>>> $cee = new C; >>>> >>>> var_dump($c->c); // [i] prints object(B), but [ii] prints int 3 >>>> var_dump($cee->c); // [i] prints object(B), and [ii] prints object(B) >>>> >>>> ?> >>>> [/code] >>>> >>>> Why does $c->c print 'int 3' ? >>>> >>>> I'm nervous to use "self::$a = $this;" because I don't want to be >>>> copying the whole object. However, isn't $this just a reference to the >>>> object, so "self::$a = $this;" is just copying the reference and not the >>>> actual object, right? >>>> >>>> Thanks in advance >>> >>> What do you think the value should be? >>> >>> A static property is bound to the class and not to an instance of the class. >>> >>> So, &A::$a is a reference to the static value. If you alter the value, >>> it will be altered for a subclasses of A and for any other reference >>> to it. >>> >> I think >> var_dump($c->c); would print object(B), but it's printing int 3. >> >> The reference is *not* being updated. I think this is a bug. What do >> you think? >> >> Thanks >> ` >> >> > > What version of PHP are you using? > I'm using: PHP Version 5.2.13 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Static Class Member References
Richard Quadling wrote: > On 13 July 2010 09:46, Richard Quadling wrote: >> On 12 July 2010 22:54, Daniel Kolbo wrote: >>> Richard Quadling wrote: >>>> On 11 July 2010 23:19, Daniel Kolbo wrote: >>>>> Hello PHPers, >>>>> >>>>> I'm having some trouble understanding some PHP behaviour. The following >>>>> example script exhibits the behaviour which I cannot understand. >>>>> [code] >>>>> >>>> >>>>> class A >>>>> { >>>>>public static $a = 3; >>>>> >>>>>function __construct() >>>>>{ >>>>>//self::$a = $this; //[i] >>>>>self::$a =& $this; //[ii] >>>>>} >>>>> } >>>>> >>>>> class B extends A >>>>> { >>>>>function __construct() >>>>>{ >>>>>parent::__construct(); >>>>>} >>>>> } >>>>> >>>>> class C { >>>>>var $c; >>>>> >>>>>function __construct() >>>>>{ >>>>>$this->c =& A::$a; >>>>>} >>>>> >>>>> } >>>>> >>>>> >>>>> $c = new C; >>>>> $b = new B; >>>>> $cee = new C; >>>>> >>>>> var_dump($c->c); // [i] prints object(B), but [ii] prints int 3 >>>>> var_dump($cee->c); // [i] prints object(B), and [ii] prints object(B) >>>>> >>>>> ?> >>>>> [/code] >>>>> >>>>> Why does $c->c print 'int 3' ? >>>>> >>>>> I'm nervous to use "self::$a = $this;" because I don't want to be >>>>> copying the whole object. However, isn't $this just a reference to the >>>>> object, so "self::$a = $this;" is just copying the reference and not the >>>>> actual object, right? >>>>> >>>>> Thanks in advance >>>> >>>> What do you think the value should be? >>>> >>>> A static property is bound to the class and not to an instance of the >>>> class. >>>> >>>> So, &A::$a is a reference to the static value. If you alter the value, >>>> it will be altered for a subclasses of A and for any other reference >>>> to it. >>>> >>> I think >>> var_dump($c->c); would print object(B), but it's printing int 3. >>> >>> The reference is *not* being updated. I think this is a bug. What do >>> you think? >>> >>> Thanks > > Aha! > > $c = new C; > > At this stage $c->c will be a reference to the static A::$a = 3. > > $b = new B; > > Now, as B's constructor calls A's constructor which replaces the > static A::$a with a reference to the instance $b, the static A::$a > should now be $b > > $cee = new C; > > At this stage $cee->c will be a reference to the static A::$a = $b. > > But, when var_dump()'d, $c->c !== $cee->c, and I think they should as > both have been assigned to a reference of a static. > > It would seem to be a bug. > > I get the same output for V5.0.0 to V5.3.3RC2 > Thanks for confirming. I reported the bug. I shortened up the test script quite a bit. Please see: Bug #52332 http://bugs.php.net/bug.php?id=52332 ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Static Class Member References
David Harkness wrote: > Ah, so assigning a reference to a variable already holding a reference > changes that variable's reference only in the same way that unsetting a > reference doesn't unset the other variables referencing the same thing, yes? > > $a = 5; > $b = &$a; > print $a; >> 5 > unset($b); // does not affect $a > print $a; >> 5 > > // and according to Mike's previous message > $b = &$a; > $c = 10; > $b = &$c; // does not affect $a > print $a >> 5 > > That makes a lot of sense. If it didn't work this way there would be no easy > way to untangle references. In the case of > > foreach($array as $key => &$value) { ... } > > the first value in the array would continuously be overwritten by the next > value. > > 1. $value gets reference to first array value > 2. on each step through the loop, the first array value would be overwritten > by the next value in the loop since $value is forever tied to it by the > initial reference assignment. > > That would be a Bad Thing (tm). > > Thanks for the clarification, Mike. > > David > The big "aha" moment for was when realizing that when assigning a reference to a variable you only change its reference and not any other variable that may also have shared the same reference. Yuck that's a mouth full. This happened when Mike said, " NOTE: since we are assigning a new reference to a variable which is already a reference, ONLY this reference changes". Yes, i agree with you David (on both of your points). Thanks for the example using the unset. This further clarified/solidified my understanding. Now, with this new understanding, I also wish to comment that if i assign (without reference) $this, i don't have to be too worried about bloating the memory, b/c i'm only assigning/copying the identifer or *handle* and not the actual object itself. In case, someone reads this in the archive the link is: http://php.net/manual/en/language.oop5.references.php Mike, thank you a ton. Regards. ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Copying an Object
Hello PHPers, I have: class A { ...code } class B extends A { ...code } $a = new A(); $b = new B(); I would like to get all of the properties of $a into $b by value. Class A extends 3 other classes. I would like a way to not have to manage a 'copy' method in B if A or one of the subclasses of A change. I was reading about clone, but this doesn't really seem to help me in this situation. How can I copy $a into $b? Thanks, dK ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Copying an Object
On 9/22/2010 9:11 AM, chris h wrote: > > You could create a method of class B that takes an object of class A as > a parameter and copies each property line by line (or method of class A > that takes an object of class B...). If you don't want to add a method > you could just do the same thing, but procedurally. The issue with this > (aside from being bad oop) is that you can't copy private properties > unless you have all the required getters and setters. The issue with > both of these is that it's ugly, high maintenance code. > > There is the iterator class, extending from which would allow you > iterate through all of your properties in a foreach, but if you don't > want to add a new method then you likely don't want to add a parent class. > > I don't care for any of these options, but as far as I know there's no > internal PHP mechanism to to copy all the properties from one object to > another object of a different class - please correct me if I'm wrong. > Is it possible that there's a more elegant solution to your problem > that does not include a mass copy of all an object's properties? (e.g. > using statics like Mr Bungle suggested or perhaps some nifty design > pattern?) > > > Chris H. > > > > > On Wed, Sep 22, 2010 at 7:35 AM, Daniel Kolbo <mailto:kolb0...@umn.edu>> wrote: > > Hello PHPers, > > I have: > > class A { >...code > } > > class B extends A { >...code > } > > $a = new A(); > > $b = new B(); > > I would like to get all of the properties of $a into $b by value. Class > A extends 3 other classes. I would like a way to not have to manage a > 'copy' method in B if A or one of the subclasses of A change. > > I was reading about clone, but this doesn't really seem to help me in > this situation. > > How can I copy $a into $b? > > Thanks, > dK > ` > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > Hello, Thank you Mr. Bungle, Chris, Nathan, and Carlos Medina. Nathan, your first response though not exactly what I was looking for was still instructive to me thanks. I almost started to implement your second response but I decided against it as I still wanted class B to extend class A (and i didn't want the unused members of A to be hanging around in the objects of B). Also, I already had __call methods implemented in the most base class level. I could have handled this by calling parent::__call from the child levels if the methods from object $a were not found. It would have worked. Instead I implemented a series of "copy" functions in each of the extended classes and cascaded through each of the extended classes. Each copy method calls parent::copy($obj) to copy the elements of the extended class. My classes weren't too crazy just 3-5 members each (all of protected typed) so it'll work for now. All in all it was a learning curve. I still think PHP needs to have this functionality built in. Say you have two classes: human and male. Further, say male extends human. Let's say you have a human object. Then later you want to make that human object a male object. This seems to be a pretty reasonable thing to request of our objects. This type of thing would especially be easy if objects of parent classes could be cast as an object of its extended class. Thanks again for all of your input, dK ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Copying an Object
> > On 9/24/2010 4:09 AM, Gary wrote: >> Daniel Kolbo wrote: >> >>> Say you have two classes: human and male. Further, say male extends >>> human. Let's say you have a human object. Then later you want to make >>> that human object a male object. This seems to be a pretty reasonable >>> thing to request of our objects. >> >> I don't think any human can change gender without major surgery, but I >> don't know if you just chose your example badly or whether you really >> think objects should be able to mutate into other types of object >> without some kind of special treatment. >> >>> This type of thing would especially be >>> easy if objects of parent classes could be cast as an object of its >>> extended class. >> >> Where would the extra data come from to fill in any fields the base >> class does not have? Just think of a simple example with a Shape class, >> extended by a ColouredShape class which contains some data about the >> object's colour - if you have a Shape object it can't become a >> ColouredShape without some surgery because bits of the ColouredShape's >> anatomy are not present. >> >> -- >> GaryPlease do NOT send me 'courtesy' replies off-list. >> PHP 5.2.12 (cli) (built: Jan 14 2010 14:54:11) >> 1.7.7(0.230/5/3) 2010-08-31 09:58 Cygwin >> >> > > The colouredShape class would probably have a member variable called > $color. This member could have a default value (as defined in the > class), be defined through the __construct() method (which would be > invoked upon such a cast procedure...perhaps there could be a __cast() > method much like how there is a __clone() method. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Copying an Object
On 9/24/2010 6:11 PM, Daniel Kolbo wrote: > On 9/24/2010 8:35 AM, Peter Lind wrote: >> On 24 September 2010 14:22, Bob McConnell wrote: >>> From: David Hutto >>> >>>> On Fri, Sep 24, 2010 at 4:09 AM, Gary wrote: >>>>> Daniel Kolbo wrote: >>>>> >>>>>> Say you have two classes: human and male. Further, say male extends >>>>>> human. Let's say you have a human object. Then later you want to make >>>>>> that human object a male object. This seems to be a pretty reasonable >>>>>> thing to request of our objects. >>>>> >>>>> I don't think any human can change gender without major surgery, but I >>>>> don't know if you just chose your example badly or whether you really >>>>> think objects should be able to mutate into other types of object >>>>> without some kind of special treatment. >>>> >>>> But it would work in something like makehuman, where you start with a >>>> neuter >>>> form and scale one way or the other for physical features. If I >>>> remember correctly, >>>> we're' all xx until you become xy(genetically speaking). >>> >>> This is one of the details that really bothers me about OOP. It makes it >>> impossible to implement some very reasonable scenarios. 80% of the time, >>> when a patron is added to a system, we don't know which gender they are. >>> More than 50% of the time, we will never know, since the client doesn't >>> keep track of it. But the rest of them will be assigned sometime after they >>> were added. i.e. the gender assignment comes from a secondary source that >>> is not available at the time the patron is entered. >>> >> >> If you can't handle that, it's not the fault of OOP but your lack of >> programming skills in OOP I'd say (and I mean no disrespect there, I'm >> just pretty sure your scenario can be handled very easily in OOP). >> >> And no, I have no urge to defend OOP in PHP, I just see this entire >> thread as a complete non-starter: if the language doesn't let you do >> something in a particular way, how about you stop, take a breather, >> then ask if perhaps there's a better way in the language to do what >> you want done? That would normally be a much more productive and >> intelligent response than either a) pressing on in the face of failure >> or b) complaining about your specific needs and how the language fails >> to meet them. >> >> Regards >> Peter >> > > I would consider the post to be a discussion among the community to > discuss possible improvements for php, to help progress the language to > handle the situations faced by the users of the language, and hey maybe > learn something along the way. I certainly wouldn't consider the post > to be an avenue to belittle members of the community. For some it's > half empty, for others half full. > ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Copying an Object
On 9/24/2010 9:49 AM, chris h wrote: > "Gang of Four" > > http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612 > > An excellent book on OOP. > > Chris H. > > > On Fri, Sep 24, 2010 at 9:34 AM, Bob McConnell wrote: > >> From: chris h >> >>> On Fri, Sep 24, 2010 at 8:35 AM, Peter Lind >> wrote: >>> >>> On 24 September 2010 14:22, Bob McConnell wrote: >>> > From: David Hutto >>> > >>> >> On Fri, Sep 24, 2010 at 4:09 AM, Gary >> wrote: >>> >>> Daniel Kolbo wrote: >>> >>> >>> >>>> Say you have two classes: human and male. Further, say >> male extends >>> >>>> human. Let's say you have a human object. Then later you >> want to make >>> >>>> that human object a male object. This seems to be a pretty >> reasonable >>> >>>> thing to request of our objects. >>> >>> >>> >>> I don't think any human can change gender without major >> surgery, but I >>> >>> don't know if you just chose your example badly or whether >> you really >>> >>> think objects should be able to mutate into other types of >> object >>> >>> without some kind of special treatment. >>> >> >>> >> But it would work in something like makehuman, where you >> start with a neuter >>> >> form and scale one way or the other for physical features. If >> I >>> >> remember correctly, >>> >> we're' all xx until you become xy(genetically speaking). >>> > >>> > This is one of the details that really bothers me about OOP. >> It makes >>> it impossible to implement some very reasonable scenarios. 80% of the >> time, >>> when a patron is added to a system, we don't know which gender they >> are. >>> More than 50% of the time, we will never know, since the client >> doesn't keep >>> track of it. But the rest of them will be assigned sometime after they >> were >>> added. i.e. the gender assignment comes from a secondary source that >> is not >>> available at the time the patron is entered. >>> > >>> If you can't handle that, it's not the fault of OOP but your >> lack of >>> programming skills in OOP I'd say (and I mean no disrespect >> there, I'm >>> just pretty sure your scenario can be handled very easily in >> OOP). >>> >>> And no, I have no urge to defend OOP in PHP, I just see this >> entire >>> thread as a complete non-starter: if the language doesn't let >> you do >>> something in a particular way, how about you stop, take a >> breather, >>> then ask if perhaps there's a better way in the language to do >> what >>> you want done? That would normally be a much more productive and >>> intelligent response than either a) pressing on in the face of >> failure >>> or b) complaining about your specific needs and how the language >> fails >>> to meet them. >>> >>> I think pages 17-19 of the GoF covers exactly this: >>> >>> "Object composition is an alternative to inheritance." ... "Any >>> [composed] object can be replaced at run-time by another as long >>> as it has the same type." >>> >>> I would look into "object composition" or just read the GoF. >> >> GoF? >> >> Bob McConnell >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> > All, Thank you for the various ideas, discussion, and book recommendation. I definitely need to check out that text. Thanks. dK ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Open Source Website Flowchart and Wireframe Software?
Hello, This is not strictly a PHP question, though i do think some members that subscribe to this list might be able to answer this question. Is there an open source website flowchart and wireframe software. My google searches are not quite pulling up what I'm looking for. I would like a piece of software that let's me layout the wireframes for various pages of a site. I would like to create a unique number for each page. On each wireframe, next to the links on that page, I would like to reference the destination of that link by the unique number of the page to which it is directed. When I'm all done with the wireframes, I would like the software to create a flowchart for the site. Other than the above, I'm looking for a very simple piece of software. Any ideas? Thanks in advance, dK ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] php application send mouse click
hello, I am mostly familiar with php for serving up web pages; however, recently i have been writing a local command line script on my WinXP machine. I have spent the better part of this last week and all of today trying to figure out a way to send a mouse click to a particular window on the screen. I first saw w32api.dll on the php.net site. However, I cannot find this dll, but this searching took me to winbinder and php-gtk2. It seems that I can only get winbinder to get (not send) mouse information: event type and x,y positions. I am not too familiar with php-gtk nor creating dlls. I want to use my local php command line script on my winXP machine to send mouse events (click) to a window. I am open to any ideas on how to do this. For C++ and VB there seems to be the SendMessage() function. Is there a way to tap into that function from my php script? winbinder has a function that wraps the SendMessage() function called wb_send_message, but after literally 9 hours i quit. Possible ideas: -Load a dll with the dl() function? (Write the dll with VB or C++) -use the w32api_register_function() in php somehow to 'tap' into windows api functions. -use a project that can assist me in this like php-gtk2 or winbinder -maybe someone has a copy of w32api.dll -something about COM objects, though i am really not familiar I am throwing out this question to the community and wondering what your suggestions would be for how to go about sending a mouse click event to my windows api from a php script. I am not interested in writing javascript as this is not a web application. Any thoughts, comments, suggestions, about how to do send mouse events from a php script will be much appreciated. Thanks in advance, -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] php local application send mouse click
Hello, I am mostly familiar with php for serving up web pages; however, recently I have been writing a local command line script on my WinXP machine. I have spent the better part of this last week and all of today trying to figure out a way to send a mouse click to a particular window on the screen. I first saw w32api.dll on the php.net site. However, I cannot find this dll, but this searching took me to winbinder and php-gtk2. It seems that I can only get winbinder to get (not send) mouse information: event type and x,y positions. I am not too familiar with php-gtk nor creating dlls. I want to use my local php command line script on my winXP machine to send mouse events (click) to a window. I am open to any ideas on how to do this. For C++ and VB there seems to be the SendMessage() function. Is there a way to tap into that function from my php script? winbinder has a function that wraps the SendMessage() function called wb_send_message, but after literally 9 hours i quit. on the MSDN.microsoft site, I saw the functions mouse_event() and SendInput() of the "user32.dll" http://msdn2.microsoft.com/en-us/library/ms646310.aspx http://msdn2.microsoft.com/en-us/library/aa932376.aspx I copied the "user32.dll" to my php/ext folder and tried loading the "user32.dll" both as an extension directive in php.ini and by using the dl() function in my script (dl() is enabled). However, both methods gave me a PHP warning: as an extension in php.ini it gives the following error: PHP Warning: PHP Startup: Invalid library (maybe not a PHP library) 'user32.dll ' in Unknown on line 0 get_loaded_extensions() confirms user32.dll never gets loaded. invoking dl("user32.dll") yields the warning: PHP Warning: dl(): Invalid library (maybe not a PHP library) 'user32.dll' in [my script] Possible ideas: -Load a dll with the dl() function? (Write the dll with VB or C++) -use the w32api_register_function() in php somehow to 'tap' into windows api functions. -use a project that can assist me in this like php-gtk2 or winbinder -maybe someone has a copy of w32api.dll -something about COM objects, though i am really not familiar It seems as though the C languages and VB languages can do this. Perhaps I could write and compile a dll in that language, somehow load it up in php (even though i am having errors doing that currently), then I can use those functions in my dll to send my mouse clicks through php. I am throwing out this question to the community and wondering what your suggestions would be for how to go about sending a mouse click event to my windows api from a php script. I am not interested in writing javascript as this is not a web application. Any thoughts, comments, suggestions, about how to do send mouse events from a php script will be much appreciated. Thanks in advance, -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Return an Array and immediately reference an index
Hello, I want to return an array from function and reference an index all in one line. Is this possible? In the code below I want I want $yo to be the array(5,6). Here is what I've tried, function returnarray() { return array('lose' => array(5,6), 'win' => array(9,8)); } $yo = returnarray()['lose']; var_dump($yo); This yields a parse error. function returnarray() { return array('lose' => array(5,6), 'win' => array(9,8)); } $yo = {returnarray()}['lose']; var_dump($yo); This yields a parse error. function returnarray() { return array('lose' => array(5,6), 'win' => array(9,8)); } $yo = ${returnarray()}['lose']; var_dump($yo); This gives notices as the result of returnarray() is being converted to a string. $yo === NULL...not what i want. function returnarray() { return array('lose' => array(5,6), 'win' => array(9,8)); } $yo = returnarray()->['lose']; var_dump($yo); This yields a parse error. function returnarray() { return array('lose' => array(5,6), 'win' => array(9,8)); } $yo = ${returnarray()}->['lose']; var_dump($yo); This yields a parse error. Thanks for your help in advance. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php local application send mouse click
Wolf wrote: Daniel Kolbo wrote: Hello, I am mostly familiar with php for serving up web pages; however, recently I have been writing a local command line script on my WinXP machine. I have spent the better part of this last week and all of today trying to figure out a way to send a mouse click to a particular window on the screen. I first saw w32api.dll on the php.net site. However, I cannot find this dll, but this searching took me to winbinder and php-gtk2. It seems that I can only get winbinder to get (not send) mouse information: event type and x,y positions. I am not too familiar with php-gtk nor creating dlls. I want to use my local php command line script on my winXP machine to send mouse events (click) to a window. I am open to any ideas on how to do this. For C++ and VB there seems to be the SendMessage() function. Is there a way to tap into that function from my php script? winbinder has a function that wraps the SendMessage() function called wb_send_message, but after literally 9 hours i quit. on the MSDN.microsoft site, I saw the functions mouse_event() and SendInput() of the "user32.dll" http://msdn2.microsoft.com/en-us/library/ms646310.aspx http://msdn2.microsoft.com/en-us/library/aa932376.aspx I copied the "user32.dll" to my php/ext folder and tried loading the "user32.dll" both as an extension directive in php.ini and by using the dl() function in my script (dl() is enabled). However, both methods gave me a PHP warning: as an extension in php.ini it gives the following error: PHP Warning: PHP Startup: Invalid library (maybe not a PHP library) 'user32.dll ' in Unknown on line 0 get_loaded_extensions() confirms user32.dll never gets loaded. invoking dl("user32.dll") yields the warning: PHP Warning: dl(): Invalid library (maybe not a PHP library) 'user32.dll' in [my script] Possible ideas: -Load a dll with the dl() function? (Write the dll with VB or C++) -use the w32api_register_function() in php somehow to 'tap' into windows api functions. -use a project that can assist me in this like php-gtk2 or winbinder -maybe someone has a copy of w32api.dll -something about COM objects, though i am really not familiar It seems as though the C languages and VB languages can do this. Perhaps I could write and compile a dll in that language, somehow load it up in php (even though i am having errors doing that currently), then I can use those functions in my dll to send my mouse clicks through php. I am throwing out this question to the community and wondering what your suggestions would be for how to go about sending a mouse click event to my windows api from a php script. I am not interested in writing javascript as this is not a web application. Any thoughts, comments, suggestions, about how to do send mouse events from a php script will be much appreciated. Thanks in advance, Trying to send one TO a screen? Good luck with that. But you really should wait at least for a few days for a response from the list before reposting the same question with no further information... What code have you tried? What code works to a point but fails? Wolf Thanks for your response Wolf. Sorry for the double email, i had just signed up, and I thought the original didn't go through, b/c i hadn't completed all the verification steps. What is TO? You referenced it in your reply. In addition to the function i mentioned from winbinder wb_send_message() I have tried: I tried loading in the user32.dll extension from within the php.ini, this failed. I tried loading in the user32.dll from within the script, this failed. dl("user32.dll") I tried loading in the php_w32api.dll from within the script (i copied the php_w32api.dll from php4 into my ext/ folder in php5. dl("php_w32api.dll"); this worked; however, when I tried registering the functions from within the script it failed on me. w32api_register_function("User32.dll", "mouse_event", "void"); I really am at a lose of how to even begin. How would I execute a mouse click from a php script on a console application? Thanks, -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Return an Array and immediately reference an index
Philip Thompson wrote: Top-posting side comment: It's not nice to hijack threads. My comments are below... On Apr 11, 2008, at 5:33 PM, Daniel Kolbo wrote: Hello, I want to return an array from function and reference an index all in one line. Is this possible? In the code below I want I want $yo to be the array(5,6). Here is what I've tried, function returnarray() { return array('lose' => array(5,6), 'win' => array(9,8)); } $yo = returnarray()['lose']; var_dump($yo); This yields a parse error. function returnarray() { return array('lose' => array(5,6), 'win' => array(9,8)); } $yo = {returnarray()}['lose']; var_dump($yo); This yields a parse error. function returnarray() { return array('lose' => array(5,6), 'win' => array(9,8)); } $yo = ${returnarray()}['lose']; var_dump($yo); This gives notices as the result of returnarray() is being converted to a string. $yo === NULL...not what i want. function returnarray() { return array('lose' => array(5,6), 'win' => array(9,8)); } $yo = returnarray()->['lose']; var_dump($yo); This yields a parse error. function returnarray() { return array('lose' => array(5,6), 'win' => array(9,8)); } $yo = ${returnarray()}->['lose']; var_dump($yo); This yields a parse error. Thanks for your help in advance. Perhaps these pages may assist you: http://php.net/manual/en/function.array.php http://php.net/functions For more immediate help, I think you want to do something along these lines: array(5,6), 'win'=>array(9,8)); return isset ($arr[$index]) ? $arr[$index] : 'Index not found'; } $returnTheValueForThis = 'lose'; $result = returnArray ($returnTheValueForThis); var_dump ($result); ?> This var_dump will return: array(2) { [0]=> int(5) [1]=> int(6) } Hope that helps. Do some more reading in the manual to help yourself out. ;) ~Philip Just to be sure, where you saying I hijacked a thread? If so, please educate me as to how i did this. Now to the response. Thanks for the response. I am familiar with the construction and returning of the arrays and referencing an index of the array. I understand your code. However, this is not what I am trying to do. I could simply do: function returnarray() { return array('lose' => array(5,6), 'win' => array(9,8)); } $yo = returnarray(); var_dump($yo['lose']); To get my desired result. I was just seeing if PHP had the capability to combine those last two lines into one. I realize the function itself is rather trivial, but just wanted some function to return an array for the sake of demonstration. Thanks, -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Quarters
It was fun! thanks tedd wrote: Hi gang: Check out my new game: http://webbytedd.com/quarters/ What do you think? Cheers, tedd PS: I originally wrote the game for the Mac over eight years ago. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Return an Array and immediately reference an index
Jim Lucas wrote: Bojan Tesanovic wrote: On Apr 12, 2008, at 12:33 AM, Daniel Kolbo wrote: Hello, I want to return an array from function and reference an index all in one line. Is this possible? In the code below I want I want $yo to be the array(5,6). Here is what I've tried, function returnarray() { return array('lose' => array(5,6), 'win' => array(9,8)); } $yo = returnarray()['lose']; var_dump($yo); This yields a parse error. function returnarray() { return array('lose' => array(5,6), 'win' => array(9,8)); } $yo = {returnarray()}['lose']; var_dump($yo); This yields a parse error. function returnarray() { return array('lose' => array(5,6), 'win' => array(9,8)); } $yo = ${returnarray()}['lose']; var_dump($yo); This gives notices as the result of returnarray() is being converted to a string. $yo === NULL...not what i want. function returnarray() { return array('lose' => array(5,6), 'win' => array(9,8)); } $yo = returnarray()->['lose']; var_dump($yo); This yields a parse error. function returnarray() { return array('lose' => array(5,6), 'win' => array(9,8)); } $yo = ${returnarray()}->['lose']; var_dump($yo); This yields a parse error. Thanks for your help in advance. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php This is not possible in PHP, though you can have a Array wrapper class function returnarray() { return new ArrayObject( array('lose' => array(5,6), 'win' => array(9,8)) ); } var_dump (returnarray()->offsetGet('lose')); or even better make you own wrapper class with __set() and __get() methods so you can have var_dump (returnarray()->lose); of course only in PHP5 Well, not quite so fast saying this is only possible in PHP5 You could do something like this. array(5,6), 'win' => array(9,8)); } print_r(returnHash()->lose); ?> Basically, this converts your newly built array into an object, using the stdClass object. Then reference the index via an object variable name instead of an array style access method. Bojan Tesanovic http://www.carster.us/ Thanks, I appreciate your comment Bojan DanK -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Return an Array and immediately reference an index
Stut wrote: On 12 Apr 2008, at 00:31, Daniel Kolbo wrote: Philip Thompson wrote: On Apr 11, 2008, at 5:33 PM, Daniel Kolbo wrote: I want to return an array from function and reference an index all in one line. Is this possible? In the code below I want I want $yo to be the array(5,6). Here is what I've tried, function returnarray() { return array('lose' => array(5,6), 'win' => array(9,8)); } $yo = returnarray()['lose']; var_dump($yo); This yields a parse error. function returnarray() { return array('lose' => array(5,6), 'win' => array(9,8)); } $yo = {returnarray()}['lose']; var_dump($yo); This yields a parse error. function returnarray() { return array('lose' => array(5,6), 'win' => array(9,8)); } $yo = ${returnarray()}['lose']; var_dump($yo); This gives notices as the result of returnarray() is being converted to a string. $yo === NULL...not what i want. function returnarray() { return array('lose' => array(5,6), 'win' => array(9,8)); } $yo = returnarray()->['lose']; var_dump($yo); This yields a parse error. function returnarray() { return array('lose' => array(5,6), 'win' => array(9,8)); } $yo = ${returnarray()}->['lose']; var_dump($yo); This yields a parse error. The PHP parser does not support this, but you may see it in a future version - it's a commonly requested feature. There are various ways to code around this limitation as other posters have stated but to me they all add far too much processing to make it worth saving a line of code and a temporary variable. -Stut Thanks Stut. By chance do you know of any proposed syntax for this feature? Or, what syntax would seem logical to you? DanK -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php local application send mouse click
Stut wrote: On 12 Apr 2008, at 00:13, Daniel Kolbo wrote: In addition to the function i mentioned from winbinder wb_send_message() I have tried: I tried loading in the user32.dll extension from within the php.ini, this failed. I tried loading in the user32.dll from within the script, this failed. dl("user32.dll") The dl function is for loading PHP extensions, not any old DLL. The same goes for the extensions section of php.ini. I tried loading in the php_w32api.dll from within the script (i copied the php_w32api.dll from php4 into my ext/ folder in php5. dl("php_w32api.dll"); this worked; however, when I tried registering the functions from within the script it failed on me. w32api_register_function("User32.dll", "mouse_event", "void"); I really am at a lose of how to even begin. How would I execute a mouse click from a php script on a console application? 1) You should be using SendInput not mouse_event unless you're on Windows 9x. 2) Why are you trying to do this in PHP? It would be much easier to develop and test in C# or VB or even C++. At the very least I'd recommend doing that to get the sequence of API calls worked out and then port it over to PHP. -Stut RE: 1) I agree. I read a lot of people were having problems with SendInput, so I just tried it with mouse_event. RE: 2) I am choosing PHP b/c i am better skilled in PHP. Alas, I have pretty much resigned to having to develop this in C# of VB. I am reading the zend page on developing php extensions. I figure I will develop the php extension in C# or VB, then load it in php. Is this what you mean by "port" to PHP? Thanks for your help, DanK -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Return an Array and immediately reference an index
Casey wrote: On Sat, Apr 12, 2008 at 9:35 AM, Nathan Nobbe <[EMAIL PROTECTED]> wrote: On Sat, Apr 12, 2008 at 12:18 PM, Casey <[EMAIL PROTECTED]> wrote: On Sat, Apr 12, 2008 at 9:12 AM, Nathan Nobbe <[EMAIL PROTECTED]> wrote: On Fri, Apr 11, 2008 at 6:33 PM, Daniel Kolbo <[EMAIL PROTECTED]> wrote: search the archives ;) http://www.mail-archive.com/php-general@lists.php.net/msg224626.html -nathan 'f', 'b' => 'g', 'c' => 'h', 'd' => 'i', 'e' => 'j'); } echo ${!${!1}=ReturnArray()}['a']; // 'f' ?> ya; i never did sit down and try to figure out how that works; care to explain ? -nathan Just awesome! Thanks for the explanation Casey, and thanks for the archived link Nathan. I knew I'd learn something by asking. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHP console script vs C/C++/C#
Hello, I am writing a PHP script for a local application (not web/html based). My script is taking a longer time to execute than I want. The source code is a few thousand lines, so I will spare you all this level of detail. I prefer to write in PHP because that is what I know best. However, I do not think there is anything inherent with my script that requires PHP over C/C++/C#. If I wrote the console application in a c language (and compiled) would one expect to see any improvements in performance? If so, how much improvement could one expect (in general)? I assume because php is not compiled that this real time interpretation of the script by the zend engine must take some time. This is why I am thinking about rewriting my whole script in a C language. But before I begin that ordeal, i wanted to ask the community for their opinions. If you think using a c language would suit me well, what language would you recommend? My google and mail archive searching for this yielded mainly PHP for web apps, so I am asking all of you. My main question is, how much of an improvement in performance will one see by using a compiled version of an application versus using a scripted version of an application? I looked at PHP's bcompiler, but the documentation is minimal so I am hesitant to dig much deeper into that, unless someone strongly suggests otherwise. Thank you PHPeeps, DanK -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP console script vs C/C++/C#
Struan Donald wrote: * at 17/04 16:30 -0500 Daniel Kolbo said: Hello, I am writing a PHP script for a local application (not web/html based). My script is taking a longer time to execute than I want. The source code is a few thousand lines, so I will spare you all this level of detail. I prefer to write in PHP because that is what I know best. However, I do not think there is anything inherent with my script that requires PHP over C/C++/C#. I think this points to an answer. If you're not too familiar with one of the compiled languages then producing code that runs faster than your current PHP implementation is a tall order. PHP, like most scripting languages, is compiled into an internal format as a first step and it's this that's then run. A lot of effort has gone into making this pretty fast and by deciding to rewrite in a compiled language you are betting that the C code, or whatever, you write will be faster. Given the effort I imagine translating a few thousand lines of PHP into one of the languages you name is likely to be significant you'd want to be sure of winning that bet. If I wrote the console application in a c language (and compiled) would one expect to see any improvements in performance? If so, how much improvement could one expect (in general)? How long will it take you to convert the program? How much more time will you spend on support and bugfixing? I assume because php is not compiled that this real time interpretation of the script by the zend engine must take some time. This is why I am thinking about rewriting my whole script in a C language. But before I begin that ordeal, i wanted to ask the community for their opinions. If you think using a c language would suit me well, what language would you recommend? It's not real time interpretation. It's a one time parse and compile when the script starts and then it runs the internal bytecode. If you have APC, or some other sort of caching mechanism installed then part of the speed up comes from caching the bytecode and saving on the initial parse and compile phase. As to what language then if you want to go ahead and do this you should pick the one you know best. If you don't know any of them that well then I really think that your time would be better spent on optimising the existing PHP code first. Are you sure it's running as fast as it can? Do you know where it's slow? Rewriting it in another language really is the 50 pound lump hammer solution to the problem if you've not tried anything else to speed it up. My google and mail archive searching for this yielded mainly PHP for web apps, so I am asking all of you. My main question is, how much of an improvement in performance will one see by using a compiled version of an application versus using a scripted version of an application? I looked at PHP's bcompiler, but the documentation is minimal so I am hesitant to dig much deeper into that, unless someone strongly suggests otherwise. A quick look at the docs tells me that all that bcompiler will do is save you the initial parse and compile phase and not speed up the execution of the code. The one thing you don't say is exactly how long is too long? Is it hours or minutes? If it's seconds then consider, as someone has suggested elsewhere in the thread, looking at APC as that should cut down the start up time of the script. HTH and apologies if none of this is news to you. Struan You are correct in that I want to be pretty sure I win the bet, before translating all the code. The code really isn't that complicated, so I think I am capable of translating it. Just a bunch of pretty small functions. The code is a simulation-model type of program, so the bottleneck in the code is the "looping". I know the exact function that takes up 86% of the time. I have tried to rewrite this function from different approaches. The bottom line is "work" needs to be done, and a lot of it. I really can't think of any other ways to improve the "logic" of the code at this time. Perhaps there are different methods I could be using to speed up execution. Again, I think the source of the issue is looping. Here is the function that takes 86% of the time...This function is called 500,000,000 times with different parameters ($arr and $arr2) (which I cannot predict their values just their size). = C O D E ===S T AR T //this function is essentially a search and remove function for a nested array foreach ($arr as $key => $value) { //count($arr) == 3 foreach ($value as $key2 => $value2) { //0<=count($value) <=1000 foreach($arr2 as $value3) { //count($arr2) == 2 if (in_array($value3, $value2)) { unset($arr[$key][$key2]);
Re: [PHP] Capitalization of variable
you could explode the string by the " " space, then use the ucword function walking through the array, then implode http://www.php.net/manual/en/function.explode.php http://www.php.net/manual/en/function.ucwords.php http://www.php.net/manual/en/function.array-walk.php http://www.php.net/manual/en/function.implode.php others: http://www.php.net/manual/en/function.ucfirst.php http://www.php.net/manual/en/ref.strings.php Dmitrii Varvashenia wrote: 2008/6/19 Ron Piggott <[EMAIL PROTECTED]>: How would I do this for a street address? If the user gave me their address as "12 george street" I would like the results to be 12 George Street. For web I use CSS: text-transform:capitalize;
Re: [PHP] Math Weirdness
I don't quite understand your problem, but I use integers for any monetary workings as you can guarantee it is accurate (obviously, you work in pence or cents rather than GBP or USD). Alex Hello Alex, I was reading through this thread, and I was curious about what methods you use to handle fractions of a dollar and/or fractions of a penny if you are always using integers. Do you only use a decimal for printing? do you adjust all interest rates, etc...then as well? How about when interest calculations result in fractions of pennies, how do you handle it then? Basically, I can't see how it could be done with just integers alone? thanks dank
[PHP] two mysql installations php_mysql.dll extension and libmysql.dll question
Hello PHP community, This question may be more for the MySQL community. If so, my apologies, please let me know. I am using php v 5.2.6. I have two versions of MySQL running on my server (windows xp home sp3). MySQL v6 is running on localhost:3306 MySQL v5.0.41 is running on localhost:3307 I have two installations of phpmyadmin (latest version 3.0.1.1) to manage both of these (i am running a local apache 2.2 server on the same machine on port 8080). Let's call these two installations phpmy5admin and phpmy6admin. I am able to login and create tables on both versions of mysql. Thus, i suspect the installation of both of these is okay. When i view both phpmyadmin installations it gives me the correct corresponding mysql version number on the homepage. However, the phpmy6admin gives me a warning saying: "Your PHP MySQL library version 5.0.51a differs from your MySQL server version 6.0.7. This may cause unpredictable behavior." When i copy the libmysql.dll from the mysql 6 installation directory into the php directory i get a pop up saying apache must shutdown when any php script invokes the mysql module. my windows path variables have C:\php;C:\Program Files\MySQL in that order. my mysql installations are at C:\Program Files\MySQL\MySQL Server 5.0 C:\Program Files\MySQL\MySQL Server 6.0 I do suspect the c:\php is being read first, as when i change the libmysql.dll in this folder, i experience different results. I do not have any libmysql.dll files in my system path. My question are: 1) Is there a libmysql.dll for version 6? If so, where do i get it? 2) Does libmysql.dll for version 6 only function properly with an updated php_mysql.dll extension? If so, where do i get this updated extension? 3) If I get the correct library for version 6 working, will i then have issues running version 5? 4) Perhaps I can ignore the warning? (i don't like this option ;) Thanks for helping me, dK
Re: [PHP] two mysql installations php_mysql.dll extension and libmysql.dll question
Daniel Kolbo wrote: Hello PHP community, This question may be more for the MySQL community. If so, my apologies, please let me know. I am using php v 5.2.6. I have two versions of MySQL running on my server (windows xp home sp3). MySQL v6 is running on localhost:3306 MySQL v5.0.41 is running on localhost:3307 I have two installations of phpmyadmin (latest version 3.0.1.1) to manage both of these (i am running a local apache 2.2 server on the same machine on port 8080). Let's call these two installations phpmy5admin and phpmy6admin. I am able to login and create tables on both versions of mysql. Thus, i suspect the installation of both of these is okay. When i view both phpmyadmin installations it gives me the correct corresponding mysql version number on the homepage. However, the phpmy6admin gives me a warning saying: "Your PHP MySQL library version 5.0.51a differs from your MySQL server version 6.0.7. This may cause unpredictable behavior." When i copy the libmysql.dll from the mysql 6 installation directory into the php directory i get a pop up saying apache must shutdown when any php script invokes the mysql module. my windows path variables have C:\php;C:\Program Files\MySQL in that order. my mysql installations are at C:\Program Files\MySQL\MySQL Server 5.0 C:\Program Files\MySQL\MySQL Server 6.0 I do suspect the c:\php is being read first, as when i change the libmysql.dll in this folder, i experience different results. I do not have any libmysql.dll files in my system path. My question are: 1) Is there a libmysql.dll for version 6? If so, where do i get it? 2) Does libmysql.dll for version 6 only function properly with an updated php_mysql.dll extension? If so, where do i get this updated extension? 3) If I get the correct library for version 6 working, will i then have issues running version 5? 4) Perhaps I can ignore the warning? (i don't like this option ;) Thanks for helping me, dK I removed the mysql5 installation and I still get the warning when viewing the phpmysql6admin. thanks, dK
Re: [PHP] two mysql installations php_mysql.dll extension and libmysql.dll question
Chris wrote: Daniel Kolbo wrote: Daniel Kolbo wrote: Hello PHP community, This question may be more for the MySQL community. If so, my apologies, please let me know. I am using php v 5.2.6. I have two versions of MySQL running on my server (windows xp home sp3). MySQL v6 is running on localhost:3306 MySQL v5.0.41 is running on localhost:3307 I have two installations of phpmyadmin (latest version 3.0.1.1) to manage both of these (i am running a local apache 2.2 server on the same machine on port 8080). Let's call these two installations phpmy5admin and phpmy6admin. I am able to login and create tables on both versions of mysql. Thus, i suspect the installation of both of these is okay. When i view both phpmyadmin installations it gives me the correct corresponding mysql version number on the homepage. However, the phpmy6admin gives me a warning saying: "Your PHP MySQL library version 5.0.51a differs from your MySQL server version 6.0.7. This may cause unpredictable behavior." When i copy the libmysql.dll from the mysql 6 installation directory into the php directory i get a pop up saying apache must shutdown when any php script invokes the mysql module. my windows path variables have C:\php;C:\Program Files\MySQL in that order. my mysql installations are at C:\Program Files\MySQL\MySQL Server 5.0 C:\Program Files\MySQL\MySQL Server 6.0 I do suspect the c:\php is being read first, as when i change the libmysql.dll in this folder, i experience different results. I do not have any libmysql.dll files in my system path. My question are: 1) Is there a libmysql.dll for version 6? If so, where do i get it? 2) Does libmysql.dll for version 6 only function properly with an updated php_mysql.dll extension? If so, where do i get this updated extension? 3) If I get the correct library for version 6 working, will i then have issues running version 5? 4) Perhaps I can ignore the warning? (i don't like this option ;) Thanks for helping me, dK I removed the mysql5 installation and I still get the warning when viewing the phpmysql6admin. because as you suspect, the libraries are different. There will be new stuff in mysql 6 compared to mysql 5. shouldn't libmysql.dll come with the mysql server? php_mysql.dll comes from php and since mysql 6 is alpha, I highly doubt that anyone from the php side of things would have put in any effort to "fix" any issues. Hello Chris, libmysql.dll does come with the mysql server as well as with the php download. I tried replacing the libmysql.dll from php with the one shipped with mysql6 as mentioned in the original post without success. To confirm, are you saying that php_mysql.dll would need to be updated in order for libmysql.dll (version for mysql6) to work correctly? Thanks, dK