Re: [PHP] No SMTP server? Can't get mail()
Probably not the solution you were looking for, but I've always found mail() very unstable and I tend to use a mail library instead. Like phpmailer or swiftmailer. Easier to configure and figure out problems with. Regards Peter
Re: [PHP] No SMTP server? Can't get mail()
On Fri, 21 Jan 2011 13:07:02 +0700, "Paul S" wrote: On Fri, 21 Jan 2011 12:28:16 +0700, Paul M Foster wrote: On Fri, Jan 21, 2011 at 10:45:46AM +0700, Paul S wrote: I am having problems with mail(). The problem is that the email just never gets there. Mail appears to be working. To start, I am investigating the SMTP server. I can't understand some things. 1) I am sure that the smtp server is and is set to "localhost", but I want to verify this ... --- error_reporting(E_ALL); echo 'display_errors = ' . ini_get('display_errors') . "\n"; echo 'register_globals = ' . ini_get('register_globals') . "\n"; echo ""; echo "SMTP host: " . ini_get("smtp"); echo "SMTP port: " . ini_get("smtp_port"); echo "Sendmail From: " . ini_get("sendmail_from"); gets: 1 1 SMTP host: SMTP port: 25 Sendmail_from: Notice: Use of undefined constant sendmail_from - assumed 'sendmail_from' in /home/ Obviously SMTP is defined (?? because it is not undefined?), but nothing is echo'd for SMTP. WHY? Think CASE-SENSITIVE. Check instead for SMTP, not smtp. YES! I started with SMTP. Same result. I then switched to smtp lower case. Switched back. Both same. I'm sorry, I should have indicated that I tried both. Still. No result from echo. sendmail_from is not defined on my machine either, for what it's worth. No problem here either. I just would like to know so that I can be sure to define it. Get's time-consuming when you can't just type in "php info". --- --- then ... ini_set( smtp, "localhost" ); gets: Notice: Use of undefined constant smtp - assumed 'smtp' in /home/ ... SMTP host: SMTP port: 25 Sendmail_from: --- Strange, SMTP was defined before , and it still won't echo. --- Again, think case-sensitive. smtp is not a valid ini variable. SMTP is. --- Both error_reporting(E_ALL); ini_set( sendmail_from, "@" ); echo "SMTP host: " . ini_get("smtp"); echo "SMTP port: " . ini_get("smtp_port"); echo "Sendmail From: " . ini_get("sendmail_from"); $return = mail('@', 'Test', 'Test'); The above is not a valid email address, as it contains a space. Not to mention, I'm not real sure about the brackets. Just use a regular email address without all the other stuff, as: jim...@example.com. var_dump($return); and error_reporting(E_ALL); ini_set( sendmail_from, "@" ); ini_set( smtp, "localhost" ); echo "SMTP host: " . ini_get("smtp"); echo "SMTP port: " . ini_get("smtp_port"); echo "Sendmail From: " . ini_get("sendmail_from"); $return = mail('@', 'Test', 'Test'); var_dump($return); return no other errors SMTP host: SMTP port: 25 Sendmail_from: @ and bool(true) Although the documentation isn't entirely clear, I suspect that the return of true from the mail() function only means that the smtp server accepted the email for delivery. The smtp server on localhost still has to connect with the remote server and the remote server has to accept the mail for delivery. I suspect the return of true only means that the origin/localhost mailserver accepts the email. It can still fail beyond there. YES YES. Same as on my PC with a windows mail server. There it DOES get to the SMTP server. My BIGGEST problem is, of course, how to figure out why it does not get to gmail.com or roadrunner.com or even my own UNIX server's email. It is the same email (text, recip, etc.). My PC server DOES forward the email to ALL addresses. My UNIX server I never get the SAME messages. But on my PC is IS forwarded to all email servers. Yet NO EMAIL is ever received/returned at the local email address or when outside email addresses are used, and never when mail() is seemingly successfully used in a script. WHY can't I echo the SMTP address being USED? What am I doing wrong? (Please note that phpinfo IS DISABLED ON MY SERVER BECAUSE IT IS A SECURITY THREAT) How am I going to get this emailing straightened out? I haven't seen a real email address used yet in your examples. Use a real address, and not a "localhost" one. A localhost address is likely not a valid one. The real addressses mentioned are in fact my personal email address at gmail.com and roadrunner.com and are "coded" here for obvious reasons. My "localhost" email addresses are at my unix server and are "coded" because I don't want to involve them specifucally. Trust me, I got those right. Thanks for your feedback which is all warranted advice on this. I agree that I believe that
Re: [PHP] No SMTP server? Can't get mail()
On Fri, 21 Jan 2011 12:28:16 +0700, Paul M Foster wrote: On Fri, Jan 21, 2011 at 10:45:46AM +0700, Paul S wrote: I am having problems with mail(). The problem is that the email just never gets there. Mail appears to be working. To start, I am investigating the SMTP server. I can't understand some things. 1) I am sure that the smtp server is and is set to "localhost", but I want to verify this ... --- error_reporting(E_ALL); echo 'display_errors = ' . ini_get('display_errors') . "\n"; echo 'register_globals = ' . ini_get('register_globals') . "\n"; echo ""; echo "SMTP host: " . ini_get("smtp"); echo "SMTP port: " . ini_get("smtp_port"); echo "Sendmail From: " . ini_get("sendmail_from"); gets: 1 1 SMTP host: SMTP port: 25 Sendmail_from: Notice: Use of undefined constant sendmail_from - assumed 'sendmail_from' in /home/ Obviously SMTP is defined (?? because it is not undefined?), but nothing is echo'd for SMTP. WHY? Think CASE-SENSITIVE. Check instead for SMTP, not smtp. YES! I started with SMTP. Same result. I then switched to smtp lower case. Switched back. Both same. I'm sorry, I should have indicated that I tried both. Still. No result from echo. sendmail_from is not defined on my machine either, for what it's worth. No problem here either. I just would like to know so that I can be sure to define it. Get's time-consuming when you can't just type in "php info". --- --- then ... ini_set( smtp, "localhost" ); gets: Notice: Use of undefined constant smtp - assumed 'smtp' in /home/ ... SMTP host: SMTP port: 25 Sendmail_from: --- Strange, SMTP was defined before , and it still won't echo. --- Again, think case-sensitive. smtp is not a valid ini variable. SMTP is. --- Both error_reporting(E_ALL); ini_set( sendmail_from, "@" ); echo "SMTP host: " . ini_get("smtp"); echo "SMTP port: " . ini_get("smtp_port"); echo "Sendmail From: " . ini_get("sendmail_from"); $return = mail('@', 'Test', 'Test'); The above is not a valid email address, as it contains a space. Not to mention, I'm not real sure about the brackets. Just use a regular email address without all the other stuff, as: jim...@example.com. var_dump($return); and error_reporting(E_ALL); ini_set( sendmail_from, "@" ); ini_set( smtp, "localhost" ); echo "SMTP host: " . ini_get("smtp"); echo "SMTP port: " . ini_get("smtp_port"); echo "Sendmail From: " . ini_get("sendmail_from"); $return = mail('@', 'Test', 'Test'); var_dump($return); return no other errors SMTP host: SMTP port: 25 Sendmail_from: @ and bool(true) Although the documentation isn't entirely clear, I suspect that the return of true from the mail() function only means that the smtp server accepted the email for delivery. The smtp server on localhost still has to connect with the remote server and the remote server has to accept the mail for delivery. I suspect the return of true only means that the origin/localhost mailserver accepts the email. It can still fail beyond there. YES YES. Same as on my PC with a windows mail server. There it DOES get to the SMTP server. My BIGGEST problem is, of course, how to figure out why it does not get to gmail.com or roadrunner.com or even my own UNIX server's email. It is the same email (text, recip, etc.). My PC server DOES forward the email to ALL addresses. My UNIX server I never get the SAME messages. But on my PC is IS forwarded to all email servers. Yet NO EMAIL is ever received/returned at the local email address or when outside email addresses are used, and never when mail() is seemingly successfully used in a script. WHY can't I echo the SMTP address being USED? What am I doing wrong? (Please note that phpinfo IS DISABLED ON MY SERVER BECAUSE IT IS A SECURITY THREAT) How am I going to get this emailing straightened out? I haven't seen a real email address used yet in your examples. Use a real address, and not a "localhost" one. A localhost address is likely not a valid one. The real addressses mentioned are in fact my personal email address at gmail.com and roadrunner.com and are "coded" here for obvious reasons. My "localhost" email addresses are at my unix server and are "coded" because I don't want to involve them specifucally. Trust me, I got those right. Thanks for your feedback which is all warranted advice on this. I agree that I believe that mail() success is only to the SMTP server and not beyond. B
[PHP] 400 Cannot connect to NNTP server
400 Cannot connect to NNTP server 76.75.200.58 (76.75.200.58:119), connect error 10060 I do not seem to be having any problems getting to this newsgroup :-) but this message keeps popping up. Just to let u know, no need for replies. Thanks for a great resource! -- Using Opera's revolutionary email client: http://www.opera.com/mail/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Organisational question: surely someone has implemented many Boolean values (tags) and a solution exist
On Thu, Jan 20, 2011 at 12:05:53PM -0800, David Harkness wrote: > On Thu, Jan 20, 2011 at 7:00 AM, Richard Quadling wrote: > > > I'd recommend using a nested set approach for the tags > > (http://dev.mysql.com/tech-resources/articles/hierarchical-data.html > > gives a good explanation on the issues and methodology of nested > > sets). > > > > Thanks for the link. That article proposes an interesting way to organize > the categories. Have you implemented this in the wild? Clearly the design > would work as it's pretty simple, and I like that it removes the need for > recursive queries. > > Dotan, the Venn diagrams are just used to explain the concept. If you use > the code to determine the left and right values, you can ignore the diagrams > entirely. As long as you're not adding/removing categories every minute, > having to recalculate left and right values isn't that big of a deal. For the curious, here is a different article which explains the same concept: http://articles.sitepoint.com/article/hierarchical-data-database Paul -- Paul M. Foster http://noferblatz.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] array to var - with different name
On Thu, Jan 20, 2011 at 05:29:01PM -0600, Donovan Brooke wrote: [snip] > > > Shawn, I don't know if I have a good reason, other than I rather like > working with string vars instead of array vars from $_REQUEST for > (sticky forms and conditionals). I can check/verify them as well in the > process. You should probably get used to dealing with the array variables. However, you can also look at the extract() function. It won't do exactly what you want, but it will pull the array keys/values into the current symbol table. Use with caution (note the second parameter to the function). Paul -- Paul M. Foster http://noferblatz.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] No SMTP server? Can't get mail()
On Fri, Jan 21, 2011 at 10:45:46AM +0700, Paul S wrote: > I am having problems with mail(). The problem is that the email just never > gets there. Mail appears to be working. To start, I am investigating the > SMTP server. I can't understand some things. > > 1) I am sure that the smtp server is and is set to "localhost", but I want > to verify this ... > > --- > error_reporting(E_ALL); > echo 'display_errors = ' . ini_get('display_errors') . "\n"; > echo 'register_globals = ' . ini_get('register_globals') . "\n"; > echo ""; > echo "SMTP host: " . ini_get("smtp"); > echo "SMTP port: " . ini_get("smtp_port"); > echo "Sendmail From: " . ini_get("sendmail_from"); > >gets: > > 1 1 > > SMTP host: > SMTP port: 25 > Sendmail_from: > Notice: Use of undefined constant sendmail_from - assumed 'sendmail_from' > in /home/ > > Obviously SMTP is defined (?? because it is not undefined?), but nothing > is echo'd for SMTP. WHY? Think CASE-SENSITIVE. Check instead for SMTP, not smtp. sendmail_from is not defined on my machine either, for what it's worth. > --- > --- > then ... > > ini_set( smtp, "localhost" ); > > gets: > > Notice: Use of undefined constant smtp - assumed 'smtp' in /home/ ... > SMTP host: > SMTP port: 25 > Sendmail_from: > --- > Strange, SMTP was defined before , and it still won't echo. > --- Again, think case-sensitive. smtp is not a valid ini variable. SMTP is. > --- > Both > > error_reporting(E_ALL); > ini_set( sendmail_from, "@" ); > echo "SMTP host: " . ini_get("smtp"); > echo "SMTP port: " . ini_get("smtp_port"); > echo "Sendmail From: " . ini_get("sendmail_from"); > $return = mail('@', 'Test', 'Test'); The above is not a valid email address, as it contains a space. Not to mention, I'm not real sure about the brackets. Just use a regular email address without all the other stuff, as: jim...@example.com. > var_dump($return); > > and > > error_reporting(E_ALL); > ini_set( sendmail_from, "@" ); > ini_set( smtp, "localhost" ); > echo "SMTP host: " . ini_get("smtp"); > echo "SMTP port: " . ini_get("smtp_port"); > echo "Sendmail From: " . ini_get("sendmail_from"); > $return = mail('@', 'Test', 'Test'); > var_dump($return); > > return > > no other errors > > SMTP host: > SMTP port: 25 > Sendmail_from: @ > > and > > bool(true) Although the documentation isn't entirely clear, I suspect that the return of true from the mail() function only means that the smtp server accepted the email for delivery. The smtp server on localhost still has to connect with the remote server and the remote server has to accept the mail for delivery. I suspect the return of true only means that the origin/localhost mailserver accepts the email. It can still fail beyond there. > > Yet NO EMAIL is ever received/returned at the local email address or when > outside email addresses are used, and never when mail() is seemingly > successfully used in a script. > > WHY can't I echo the SMTP address being USED? What am I doing wrong? > (Please note that phpinfo IS DISABLED ON MY SERVER BECAUSE IT IS A > SECURITY THREAT) > > How am I going to get this emailing straightened out? I haven't seen a real email address used yet in your examples. Use a real address, and not a "localhost" one. A localhost address is likely not a valid one. Paul -- Paul M. Foster http://noferblatz.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] No SMTP server? Can't get mail()
I am having problems with mail(). The problem is that the email just never gets there. Mail appears to be working. To start, I am investigating the SMTP server. I can't understand some things. 1) I am sure that the smtp server is and is set to "localhost", but I want to verify this ... --- error_reporting(E_ALL); echo 'display_errors = ' . ini_get('display_errors') . "\n"; echo 'register_globals = ' . ini_get('register_globals') . "\n"; echo ""; echo "SMTP host: " . ini_get("smtp"); echo "SMTP port: " . ini_get("smtp_port"); echo "Sendmail From: " . ini_get("sendmail_from"); gets: 1 1 SMTP host: SMTP port: 25 Sendmail_from: Notice: Use of undefined constant sendmail_from - assumed 'sendmail_from' in /home/ Obviously SMTP is defined (?? because it is not undefined?), but nothing is echo'd for SMTP. WHY? --- --- then ... ini_set( smtp, "localhost" ); gets: Notice: Use of undefined constant smtp - assumed 'smtp' in /home/ ... SMTP host: SMTP port: 25 Sendmail_from: --- Strange, SMTP was defined before , and it still won't echo. --- --- Both error_reporting(E_ALL); ini_set( sendmail_from, "@" ); echo "SMTP host: " . ini_get("smtp"); echo "SMTP port: " . ini_get("smtp_port"); echo "Sendmail From: " . ini_get("sendmail_from"); $return = mail('@', 'Test', 'Test'); var_dump($return); and error_reporting(E_ALL); ini_set( sendmail_from, "@" ); ini_set( smtp, "localhost" ); echo "SMTP host: " . ini_get("smtp"); echo "SMTP port: " . ini_get("smtp_port"); echo "Sendmail From: " . ini_get("sendmail_from"); $return = mail('@', 'Test', 'Test'); var_dump($return); return no other errors SMTP host: SMTP port: 25 Sendmail_from: @ and bool(true) Yet NO EMAIL is ever received/returned at the local email address or when outside email addresses are used, and never when mail() is seemingly successfully used in a script. WHY can't I echo the SMTP address being USED? What am I doing wrong? (Please note that phpinfo IS DISABLED ON MY SERVER BECAUSE IT IS A SECURITY THREAT) How am I going to get this emailing straightened out? -- Using Opera's revolutionary email client: http://www.opera.com/mail/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] possible namespace bug?
On Thu, Jan 20, 2011 at 4:26 PM, Tommy Pham wrote: > Anyway, I found the problem: \N in > > use org\puremvc\php\patterns\observer\Notifier; > AFAIK \n is only processed inside double-quoted strings and here-docs. The \N has no special meaning beyond a namespace separator and a capital N. My guess is the same as Adam's. Since I don't see how you declare INotification, I think it's getting confused when using namespaces. In the top part, PHP assumes the class must be in the org\puremvc\php\interfaces namespace whereas in SimpleCommand's declaration, INotification is assumed to be in the org\puremvc\php\patterns\command namespace. This causes their declarations to be mismatched. David
Re: [PHP] email address syntax checker
Hej Nisse, Me thinks it isn't a valid address :-). -- With best regards from Ukraine, Andre Skype: Francophile My blog: http://oire.org/menelion (mostly in Russian) Twitter: http://twitter.com/m_elensule Facebook: http://facebook.com/menelion Original message From: Nisse Engström To: php-general@lists.php.net Date created: , 2:25:01 AM Subject: [PHP] email address syntax checker On Thu, 20 Jan 2011 19:03:22 +0530, Nilesh Govindarajan wrote: > Well, I had created an email validator long ago, after a neat research > on Google, reading RFCs, etc. > I don't guarantee that it's without bugs, but it has been correct for me > in all valid & invalid email addresses I used for test. > > Code: > > > function checkMail($mail) { > >if(strlen($mail) <= 0) { > return false; >} > >$split = explode('@', $mail); > >if(count($split) > 2) { > return false; >} <"@"@example.com> is not a valid address? /Nisse -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] possible namespace bug?
On Thu, Jan 20, 2011 at 3:49 PM, Adam Richardson wrote: > On Thu, Jan 20, 2011 at 5:33 PM, Tommy Pham wrote: >> >> Hi folks, >> >> I thought I try implementing namesapce on one the ported apps I did a >> while >> back but ran into a problem. First the code: >> >> //namespace org\puremvc\php\interfaces; >> >> interface ICommand >> { >> function execute(INotification $notification); >> } >> interface INotifier >> { >> function sendNotification($notificationName, $body = null, $type = >> null); >> } >> >> //-- >> --- >> //namespace org\puremvc\php\patterns\observer; >> //use org\puremvc\php\interfaces\INotifier; >> >> class Notifier implements INotifier >> { >> public function __construct() { echo __METHOD__; } >> public function sendNotification($notificationName, $body = null, $type >> = null) >> { >> } >> } >> >> //-- >> --- >> //namespace org\puremvc\php\patterns\command; >> //use org\puremvc\php\interfaces\ICommand; >> //use org\puremvc\php\interfaces\INotifier; >> //use org\puremvc\php\patterns\observer\Notifier; >> >> class SimpleCommand extends Notifier implements ICommand, INotifier >> { >> public function __construct() { parent::__construct(); echo ' -> '; >> echo __METHOD__; } >> function execute(INotification $notification) { } >> } > > Where's the INotification namespace? If it's in org\puremvc\php\interfaces, > you'll have to include it, too. I see you just included the whole set of > interfaces in the top part of the example. Maybe you just omitted the code, > but that could be the problem. > Adam > > -- > Nephtali: A simple, flexible, fast, and security-focused PHP framework > http://nephtaliproject.com > Hi Adam, The error didn't complain about that even if I use without the namespace... possible bug? :)) Anyway, I found the problem: \N in use org\puremvc\php\patterns\observer\Notifier; I think I should submit request for change from \ to / to prevent escaping. and makes using of namespace more natural. Thanks, Tommy -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] email address syntax checker
On Thu, 20 Jan 2011 19:03:22 +0530, Nilesh Govindarajan wrote: > Well, I had created an email validator long ago, after a neat research > on Google, reading RFCs, etc. > I don't guarantee that it's without bugs, but it has been correct for me > in all valid & invalid email addresses I used for test. > > Code: > > > function checkMail($mail) { > >if(strlen($mail) <= 0) { > return false; >} > >$split = explode('@', $mail); > >if(count($split) > 2) { > return false; >} <"@"@example.com> is not a valid address? /Nisse -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] possible namespace bug?
On Thu, Jan 20, 2011 at 5:33 PM, Tommy Pham wrote: > Hi folks, > > I thought I try implementing namesapce on one the ported apps I did a while > back but ran into a problem. First the code: > > //namespace org\puremvc\php\interfaces; > > interface ICommand > { >function execute(INotification $notification); > } > interface INotifier > { >function sendNotification($notificationName, $body = null, $type = > null); > } > > //-- > --- > //namespace org\puremvc\php\patterns\observer; > //use org\puremvc\php\interfaces\INotifier; > > class Notifier implements INotifier > { >public function __construct() { echo __METHOD__; } >public function sendNotification($notificationName, $body = null, $type > = null) >{ >} > } > > //-- > --- > //namespace org\puremvc\php\patterns\command; > //use org\puremvc\php\interfaces\ICommand; > //use org\puremvc\php\interfaces\INotifier; > //use org\puremvc\php\patterns\observer\Notifier; > > class SimpleCommand extends Notifier implements ICommand, INotifier > { >public function __construct() { parent::__construct(); echo ' -> '; > echo __METHOD__; } >function execute(INotification $notification) { } > } > Where's the INotification namespace? If it's in org\puremvc\php\interfaces, you'll have to include it, too. I see you just included the whole set of interfaces in the top part of the example. Maybe you just omitted the code, but that could be the problem. Adam -- Nephtali: A simple, flexible, fast, and security-focused PHP framework http://nephtaliproject.com
RE: [PHP] array to var - with different name
> -Original Message- > From: Donovan Brooke [mailto:li...@euca.us] > Sent: Thursday, January 20, 2011 3:29 PM > Cc: php-general@lists.php.net > Subject: Re: [PHP] array to var - with different name > > Tommy Pham wrote: > [snip] > >> foreach ($_REQUEST as $key => $value) $$key = $value; > >> > >> short-circuited one-liners :) > >> > >> Regards, > >> Tommy > >> > > > > akk... wrong clicked before I had a chance to fix the code. anyway, > > > > foreach ($_GET as $key => $value) if (substr($key, 0, 2) == 'f_') > > ${'t_'.substr($key, 2)} = $value; > > > Tommy, excellent.. I had just rewrote your first suggestion: > > foreach ($a_formvars as $key => $value) ${str_replace('f_', 't_',$key)} = > $value; > > (which works) > but I like that you are only affecting the vars that *begin* with $match. I > suppose the above would also work with $_REQUEST. > > > > Shawn, I don't know if I have a good reason, other than I rather like > working with string vars instead of array vars from $_REQUEST for > (sticky forms and conditionals). I can check/verify them as well in the > process. > > Thanks to all that posted.. I always learn from the "skin the cat" game. > > Donovan > > > -- > D Brooke > I advice strongly against str_replace if you're looking specifically 'f_' at the __beginning__ of the string. substr would guarantee it. Regards, Tommy -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] array to var - with different name
Tommy Pham wrote: [snip] foreach ($_REQUEST as $key => $value) $$key = $value; short-circuited one-liners :) Regards, Tommy akk... wrong clicked before I had a chance to fix the code. anyway, foreach ($_GET as $key => $value) if (substr($key, 0, 2) == 'f_') ${'t_'.substr($key, 2)} = $value; Tommy, excellent.. I had just rewrote your first suggestion: foreach ($a_formvars as $key => $value) ${str_replace('f_', 't_',$key)} = $value; (which works) but I like that you are only affecting the vars that *begin* with $match. I suppose the above would also work with $_REQUEST. Shawn, I don't know if I have a good reason, other than I rather like working with string vars instead of array vars from $_REQUEST for (sticky forms and conditionals). I can check/verify them as well in the process. Thanks to all that posted.. I always learn from the "skin the cat" game. Donovan -- D Brooke -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: array to var - with different name
On Thu, Jan 20, 2011 at 2:49 PM, Shawn McKenzie wrote: > On 01/20/2011 04:28 PM, Donovan Brooke wrote: >> Hello again! >> >> I'm trying to find a good way to convert array key/value's to >> variable name values... but with the caveat of the name being >> slightly different than the original key >> (to fit my naming conventions). >> >> first, I (tediously) did this: >> >> --- >> if (isset($_GET['f_action'])) { >> $t_action = $_GET['f_action']; >> } >> >> if (isset($_POST['f_action'])) { >> $t_action = $_POST['f_action']; >> } >> >> if (isset($_GET['f_ap'])) { >> $t_ap = $_GET['f_ap']; >> } >> >> if (isset($_POST['f_ap'])) { >> $t_ap = $_POST['f_ap']; >> } >> --- >> >> Instead, I wanted to find *all* incoming "f_" keys in the POST/GET >> array, and convert them to a variable name consisting of "t_" in one >> statement. >> >> I then did this test and it appears to work (sorry for email line breaks): >> >> - >> $a_formvars = array('f_1' => '1','f_2' => '2','f_3' => '3','f_4' => >> '4','f_5' => '5','f_6' => '6',); >> >> $t_string = ""; >> foreach ($a_formvars as $key => $value) { >> if (substr($key,0,2) == 'f_') { >> $t_string = $t_string . "t_" . substr($key,2) . "=$value&"; >> parse_str($t_string); >> } >> } >> - >> >> I figure I can adapt the above by doing something like: >> >> $a_formvars = array_merge($_POST,$_GET); >> >> However, I thought I'd check with you all to see if there is something >> I'm missing. I don't speak PHP that well and there may be an easier way. >> >> Thanks, >> Donovan >> >> > > I'm sure you have a good reason for doing this? It is needlessly adding > complexity, but here is a one liner (not tested): > > extract(array_combine(str_replace('f_', 't_', array_keys($_POST)), > array_values($_POST))); > > -- > Thanks! > -Shawn > http://www.spidean.com > That will fail if by chance that he has a form name set to a_f_something or similar along the line. Or a possible attack that comes in the form submission. Regards, Tommy -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] array to var - with different name
On Thu, Jan 20, 2011 at 3:09 PM, Tommy Pham wrote: > On Thu, Jan 20, 2011 at 2:28 PM, Donovan Brooke wrote: >> Hello again! >> >> I'm trying to find a good way to convert array key/value's to >> variable name values... but with the caveat of the name being >> slightly different than the original key >> (to fit my naming conventions). >> >> first, I (tediously) did this: >> >> --- >> if (isset($_GET['f_action'])) { >> $t_action = $_GET['f_action']; >> } >> >> if (isset($_POST['f_action'])) { >> $t_action = $_POST['f_action']; >> } >> >> if (isset($_GET['f_ap'])) { >> $t_ap = $_GET['f_ap']; >> } >> >> if (isset($_POST['f_ap'])) { >> $t_ap = $_POST['f_ap']; >> } >> --- >> >> Instead, I wanted to find *all* incoming "f_" keys in the POST/GET array, >> and convert them to a variable name consisting of "t_" in one statement. >> >> I then did this test and it appears to work (sorry for email line breaks): >> >> - >> $a_formvars = array('f_1' => '1','f_2' => '2','f_3' => '3','f_4' => >> '4','f_5' => '5','f_6' => '6',); >> >> $t_string = ""; >> foreach ($a_formvars as $key => $value) { >> if (substr($key,0,2) == 'f_') { >> $t_string = $t_string . "t_" . substr($key,2) . "=$value&"; >> parse_str($t_string); >> } >> } >> - >> >> I figure I can adapt the above by doing something like: >> >> $a_formvars = array_merge($_POST,$_GET); >> >> However, I thought I'd check with you all to see if there is something >> I'm missing. I don't speak PHP that well and there may be an easier way. >> >> Thanks, >> Donovan >> >> >> -- >> D Brooke >> > > foreach ($_GET as $key => $value) $$key = $value; > foreach ($_POST as $key => $value) $$key = $value; > > or > > foreach ($_REQUEST as $key => $value) $$key = $value; > > short-circuited one-liners :) > > Regards, > Tommy > akk... wrong clicked before I had a chance to fix the code. anyway, foreach ($_GET as $key => $value) if (substr($key, 0, 2) == 'f_') ${'t_'.substr($key, 2)} = $value; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] array to var - with different name
On Thu, Jan 20, 2011 at 2:28 PM, Donovan Brooke wrote: > Hello again! > > I'm trying to find a good way to convert array key/value's to > variable name values... but with the caveat of the name being > slightly different than the original key > (to fit my naming conventions). > > first, I (tediously) did this: > > --- > if (isset($_GET['f_action'])) { > $t_action = $_GET['f_action']; > } > > if (isset($_POST['f_action'])) { > $t_action = $_POST['f_action']; > } > > if (isset($_GET['f_ap'])) { > $t_ap = $_GET['f_ap']; > } > > if (isset($_POST['f_ap'])) { > $t_ap = $_POST['f_ap']; > } > --- > > Instead, I wanted to find *all* incoming "f_" keys in the POST/GET array, > and convert them to a variable name consisting of "t_" in one statement. > > I then did this test and it appears to work (sorry for email line breaks): > > - > $a_formvars = array('f_1' => '1','f_2' => '2','f_3' => '3','f_4' => > '4','f_5' => '5','f_6' => '6',); > > $t_string = ""; > foreach ($a_formvars as $key => $value) { > if (substr($key,0,2) == 'f_') { > $t_string = $t_string . "t_" . substr($key,2) . "=$value&"; > parse_str($t_string); > } > } > - > > I figure I can adapt the above by doing something like: > > $a_formvars = array_merge($_POST,$_GET); > > However, I thought I'd check with you all to see if there is something > I'm missing. I don't speak PHP that well and there may be an easier way. > > Thanks, > Donovan > > > -- > D Brooke > foreach ($_GET as $key => $value) $$key = $value; foreach ($_POST as $key => $value) $$key = $value; or foreach ($_REQUEST as $key => $value) $$key = $value; short-circuited one-liners :) Regards, Tommy -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: array to var - with different name
On 01/20/2011 04:28 PM, Donovan Brooke wrote: > Hello again! > > I'm trying to find a good way to convert array key/value's to > variable name values... but with the caveat of the name being > slightly different than the original key > (to fit my naming conventions). > > first, I (tediously) did this: > > --- > if (isset($_GET['f_action'])) { > $t_action = $_GET['f_action']; > } > > if (isset($_POST['f_action'])) { > $t_action = $_POST['f_action']; > } > > if (isset($_GET['f_ap'])) { > $t_ap = $_GET['f_ap']; > } > > if (isset($_POST['f_ap'])) { > $t_ap = $_POST['f_ap']; > } > --- > > Instead, I wanted to find *all* incoming "f_" keys in the POST/GET > array, and convert them to a variable name consisting of "t_" in one > statement. > > I then did this test and it appears to work (sorry for email line breaks): > > - > $a_formvars = array('f_1' => '1','f_2' => '2','f_3' => '3','f_4' => > '4','f_5' => '5','f_6' => '6',); > > $t_string = ""; > foreach ($a_formvars as $key => $value) { > if (substr($key,0,2) == 'f_') { > $t_string = $t_string . "t_" . substr($key,2) . "=$value&"; > parse_str($t_string); > } > } > - > > I figure I can adapt the above by doing something like: > > $a_formvars = array_merge($_POST,$_GET); > > However, I thought I'd check with you all to see if there is something > I'm missing. I don't speak PHP that well and there may be an easier way. > > Thanks, > Donovan > > I'm sure you have a good reason for doing this? It is needlessly adding complexity, but here is a one liner (not tested): extract(array_combine(str_replace('f_', 't_', array_keys($_POST)), array_values($_POST))); -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] possible namespace bug?
Hi folks, I thought I try implementing namesapce on one the ported apps I did a while back but ran into a problem. First the code: //namespace org\puremvc\php\interfaces; interface ICommand { function execute(INotification $notification); } interface INotifier { function sendNotification($notificationName, $body = null, $type = null); } //-- --- //namespace org\puremvc\php\patterns\observer; //use org\puremvc\php\interfaces\INotifier; class Notifier implements INotifier { public function __construct() { echo __METHOD__; } public function sendNotification($notificationName, $body = null, $type = null) { } } //-- --- //namespace org\puremvc\php\patterns\command; //use org\puremvc\php\interfaces\ICommand; //use org\puremvc\php\interfaces\INotifier; //use org\puremvc\php\patterns\observer\Notifier; class SimpleCommand extends Notifier implements ICommand, INotifier { public function __construct() { parent::__construct(); echo ' -> '; echo __METHOD__; } function execute(INotification $notification) { } } //-- --- //echo ''; new \org\puremvc\php\patterns\observer\Notifier(); //echo ''; new \org\puremvc\php\patterns\command\SimpleCommand(); The above works as expected without namespace. When I uncomment the lines namespace/use, I get this error: Fatal error: Declaration of org\puremvc\php\patterns\command\SimpleCommand::execute() must be compatible with that of org\puremvc\php\interfaces\ICommand::execute() on line 30. Line 30 is the class SimpleCommand declaration. Anyone having similar problems? My platform is PHP 5.3.5 VC9 NTS as FastCGI on Win08r2 x64. Thanks, Tommy -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] array to var - with different name
On Thursday 20 January 2011, Donovan Brooke wrote: > Hello again! > > I'm trying to find a good way to convert array key/value's to > variable name values... but with the caveat of the name being > slightly different than the original key > (to fit my naming conventions). > > first, I (tediously) did this: > > --- > if (isset($_GET['f_action'])) { >$t_action = $_GET['f_action']; > } > > if (isset($_POST['f_action'])) { >$t_action = $_POST['f_action']; > } > > if (isset($_GET['f_ap'])) { >$t_ap = $_GET['f_ap']; > } > > if (isset($_POST['f_ap'])) { >$t_ap = $_POST['f_ap']; > } > --- > > Instead, I wanted to find *all* incoming "f_" keys in the POST/GET > array, and convert them to a variable name consisting of "t_" in one > statement. That was ver tedious... > > I then did this test and it appears to work (sorry for email line > breaks): > > - > $a_formvars = array('f_1' => '1','f_2' => '2','f_3' => '3','f_4' => > '4','f_5' => '5','f_6' => '6',); > > $t_string = ""; > foreach ($a_formvars as $key => $value) { >if (substr($key,0,2) == 'f_') { > $t_string = $t_string . "t_" . substr($key,2) . "=$value&"; > parse_str($t_string); >} > } > - > > I figure I can adapt the above by doing something like: > > $a_formvars = array_merge($_POST,$_GET); > > However, I thought I'd check with you all to see if there is something > I'm missing. I don't speak PHP that well and there may be an easier way. Did you tried the $_REQUEST variable? Take a look on: > > Thanks, > Donovan Best regards, -- Daniel Molina Wegener System Programmer & Web Developer Phone: +56 (2) 979-0277 | Blog: http://coder.cl/
[PHP] array to var - with different name
Hello again! I'm trying to find a good way to convert array key/value's to variable name values... but with the caveat of the name being slightly different than the original key (to fit my naming conventions). first, I (tediously) did this: --- if (isset($_GET['f_action'])) { $t_action = $_GET['f_action']; } if (isset($_POST['f_action'])) { $t_action = $_POST['f_action']; } if (isset($_GET['f_ap'])) { $t_ap = $_GET['f_ap']; } if (isset($_POST['f_ap'])) { $t_ap = $_POST['f_ap']; } --- Instead, I wanted to find *all* incoming "f_" keys in the POST/GET array, and convert them to a variable name consisting of "t_" in one statement. I then did this test and it appears to work (sorry for email line breaks): - $a_formvars = array('f_1' => '1','f_2' => '2','f_3' => '3','f_4' => '4','f_5' => '5','f_6' => '6',); $t_string = ""; foreach ($a_formvars as $key => $value) { if (substr($key,0,2) == 'f_') { $t_string = $t_string . "t_" . substr($key,2) . "=$value&"; parse_str($t_string); } } - I figure I can adapt the above by doing something like: $a_formvars = array_merge($_POST,$_GET); However, I thought I'd check with you all to see if there is something I'm missing. I don't speak PHP that well and there may be an easier way. Thanks, Donovan -- D Brooke -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] RE: Organisational question: surely someone has implemented many Boolean values (tags) and a solution exist
>> [JS] I disagree. The method I proposed can be extended to any depth, and >> any >> leaf or branch can be retrieved with a single query. >> > >I suppose for retrievals this structure has advantages, but unless >MySQL has a ++ operator (or better yet, one that adds or subtracts 2 >from an int) then it looks to be a pain to add nodes. > [JS] Not at all. Somebody, somehow, has to assign a name to the tag and designate its place in the hierarchy. I don't see how you can avoid that being done by a human. Regards, Jerry Schwartz Global Information Incorporated 195 Farmington Ave. Farmington, CT 06032 860.674.8796 / FAX: 860.674.8341 E-mail: je...@gii.co.jp Web site: www.the-infoshop.com >But I will play with the idea. Maybe after I write the code (I'm >saving that for tomorrow) I'll see it differently. Thanks. > >-- >Dotan Cohen > >http://gibberish.co.il >http://what-is-what.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Organisational question: surely someone has implemented many Boolean values (tags) and a solution exist
On Thu, Jan 20, 2011 at 12:21 PM, Dotan Cohen wrote: > I understood that. My concern is exactly with adding new nodes. There > is no incrementor (++i) in SQL, so knowingly coding a solution that > will require incrementing two fields in half the database rows seems > irresponsible. > It only requires updating the category rows. If you have several hundred categories this is a non-issue. If you have several thousand categories, you probably have millions of products, and you'd want to do some performance analysis on it. Even still, this is necessary only when adding new categories. If you are doing this often, you could leave spaces in the left and right values so that you could minimize the number of rows that need to be updated. The article makes every leaf use x and x+1 for left and right which forces another update to add a child. If instead you used x and x+20 you'd leave space for more children without any updates. This could be applied from top to bottom, starting with the root category getting 0 and MAX_INT for its values. However, it's probably not even worth applying that complexity until you prove that frequent category additions are causing problems. Most systems will be querying against the categories table far more frequently, and that's where this model pays off. If you want to see all products in category X and its subcategories, it's a single *non-recursive* query. That's huge if you are doing a lot of searches like this. But what a mess this would be if the two methods go out of sync! > Sure, but these values would be maintained by your code--not end-users. It just comes down to making sure your code is correct through appropriate unit tests. By moving the logic to a stored procedure, you can ensure the table is locked during the updates to keep two users from adding a new category simultaneously. That pays off more? For the guy writing code or for the database > memory requirement? > Performance-wise. The nested set method looks to be moderately more complex code-wise, but luckily that is done just once while querying the database is done again and again. As with all optimizations, it's best to measure and make sure there's a problem before trying to solve it. Once you've built a few hierarchical systems, you'll be able to make a gut call up front. Only two update statements, but they are affecting on average half the > database's rows! > Of a single table: categories. Hopefully you have far more items that get categorized than you do categories. > Which do you call the hierarchical model? That term is not used in the > linked article. > Well, both models are hierarchical in the sense that there's a parent-child relationship. By hierarchical here I mean that the method of implementation involves each category pointing to its parent directly via a parent_id column. Searching for all subcategories of category X requires searching first for all children, then all grandchildren, and so on, resulting in a recursive query. Using the nested sets model requires a single non-recursive query to get the same data. David
Re: [PHP] Organisational question: surely someone has implemented many Boolean values (tags) and a solution exist
On Thu, Jan 20, 2011 at 22:05, David Harkness wrote: > Thanks for the link. That article proposes an interesting way to organize > the categories. Have you implemented this in the wild? Clearly the design > would work as it's pretty simple, and I like that it removes the need for > recursive queries. I am also interested in knowing if this approach is used in any production code. > Dotan, the Venn diagrams are just used to explain the concept. If you use > the code to determine the left and right values, you can ignore the diagrams > entirely. As long as you're not adding/removing categories every minute, > having to recalculate left and right values isn't that big of a deal. I understood that. My concern is exactly with adding new nodes. There is no incrementor (++i) in SQL, so knowingly coding a solution that will require incrementing two fields in half the database rows seems irresponsible. > Also, there's no reason you couldn't keep the parent_id field with the > nested sets. It would come in handy for certain types of queries, though > it's not necessary. That is true. I could store both methods, and experiment to see which is preferable. But what a mess this would be if the two methods go out of sync! Isn't there a name for that in SQL, something along the lines of not storing the same data in two places lest one should change and not the other? The term escapes me. >> I disagree. The method I proposed can be extended to any depth, and any >> leaf or branch can be retrieved with a single query. > > The nested set method can be extended to any depth, and it pays off more the > larger the hierarchy grows. While you can retrieve any branch (all > ancestors) of a node with a single SQL query, the SQL engine itself actually > must perform a recursive query meaning multiple hits on the parent_id index. That pays off more? For the guy writing code or for the database memory requirement? >> I suppose for retrievals this structure has advantages, but unless >> MySQL has a ++ operator (or better yet, one that adds or subtracts 2 >> from an int) then it looks to be a pain to add nodes. > > ++ or += wouldn't be any better here than x = x + 2. Once you're modifying > indexed values, you'll pay a much higher price writing to disk than += could > ever save you in CPU cycles. The beauty is that inserting a node requires > only two update statements that will fix *all* categories that need to be > adjusted. Only two update statements, but they are affecting on average half the database's rows! > Adding categories to the hierarchical model is definitely faster > so it comes down to your insert-to-select ratio. Moving a subtree is also > much easier with the hierarchical model. Which do you call the hierarchical model? That term is not used in the linked article. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Organisational question: surely someone has implemented many Boolean values (tags) and a solution exist
On Thu, Jan 20, 2011 at 7:00 AM, Richard Quadling wrote: > I'd recommend using a nested set approach for the tags > (http://dev.mysql.com/tech-resources/articles/hierarchical-data.html > gives a good explanation on the issues and methodology of nested > sets). > Thanks for the link. That article proposes an interesting way to organize the categories. Have you implemented this in the wild? Clearly the design would work as it's pretty simple, and I like that it removes the need for recursive queries. Dotan, the Venn diagrams are just used to explain the concept. If you use the code to determine the left and right values, you can ignore the diagrams entirely. As long as you're not adding/removing categories every minute, having to recalculate left and right values isn't that big of a deal. Also, there's no reason you couldn't keep the parent_id field with the nested sets. It would come in handy for certain types of queries, though it's not necessary. On Thu, Jan 20, 2011 at 11:40 AM, Jerry Schwartz wrote: > I disagree. The method I proposed can be extended to any depth, and any > leaf or branch can be retrieved with a single query. > The nested set method can be extended to any depth, and it pays off more the larger the hierarchy grows. While you can retrieve any branch (all ancestors) of a node with a single SQL query, the SQL engine itself actually must perform a recursive query meaning multiple hits on the parent_id index. On Thu, Jan 20, 2011 at 11:59 AM, Dotan Cohen wrote: > I suppose for retrievals this structure has advantages, but unless > MySQL has a ++ operator (or better yet, one that adds or subtracts 2 > from an int) then it looks to be a pain to add nodes. > ++ or += wouldn't be any better here than x = x + 2. Once you're modifying indexed values, you'll pay a much higher price writing to disk than += could ever save you in CPU cycles. The beauty is that inserting a node requires only two update statements that will fix *all* categories that need to be adjusted. Adding categories to the hierarchical model is definitely faster so it comes down to your insert-to-select ratio. Moving a subtree is also much easier with the hierarchical model. David
Re: [PHP] RE: Organisational question: surely someone has implemented many Boolean values (tags) and a solution exist
On Thu, Jan 20, 2011 at 21:40, Jerry Schwartz wrote: >>Thanks. I prefer the "parent tag" field, though, I feel that it is >>more flexible. >> >> > [JS] I disagree. The method I proposed can be extended to any depth, and any > leaf or branch can be retrieved with a single query. > I suppose for retrievals this structure has advantages, but unless MySQL has a ++ operator (or better yet, one that adds or subtracts 2 from an int) then it looks to be a pain to add nodes. But I will play with the idea. Maybe after I write the code (I'm saving that for tomorrow) I'll see it differently. Thanks. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] RE: Organisational question: surely someone has implemented many Boolean values (tags) and a solution exist
On Thu, Jan 20, 2011 at 2:40 PM, Jerry Schwartz wrote: >>-Original Message- >>From: Dotan Cohen [mailto:dotanco...@gmail.com] >>Sent: Thursday, January 20, 2011 11:25 AM >>To: Jerry Schwartz >>Cc: mysql.; php-general. >>Subject: Re: Organisational question: surely someone has implemented many >>Boolean values (tags) and a solution exist >> >> >>> As for setting up a hierarchy, that's trickier. One way to handle that is >>> to >>> work like libraries do: 10 is "fiction", 10.05 is "crime novels", 10.05.07 >>> is >>> "British authors", and so forth. Your `tags` table then looks like >>> >> >>Thanks. I prefer the "parent tag" field, though, I feel that it is >>more flexible. >> >> > [JS] I disagree. The method I proposed can be extended to any depth, and any > leaf or branch can be retrieved with a single query. No one argues with method of implementation(not that i explored the individual ideas), but with that available, you can hierarchy the concept of your db conceptualization. > > Regards, > > Jerry Schwartz > Global Information Incorporated > 195 Farmington Ave. > Farmington, CT 06032 > > 860.674.8796 / FAX: 860.674.8341 > E-mail: je...@gii.co.jp > Web site: www.the-infoshop.com > > > >>-- >>Dotan Cohen >> >>http://gibberish.co.il >>http://what-is-what.com > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- The lawyer in me says argue...even if you're wrong. The scientist in me... says shut up, listen, and then argue. But the lawyer won on appeal, so now I have to argue due to a court order. Furthermore, if you could be a scientific celebrity, would you want einstein sitting around with you on saturday morning, while you're sitting in your undies, watching Underdog?...Or better yet, would Einstein want you to violate his Underdog time? Can you imagine Einstein sitting around in his underware? Thinking about the relativity between his pubic nardsac, and his Fruit of the Looms, while knocking a few Dorito's crumbs off his inner brilliant white thighs, and hailing E = mc**2, and licking the orangy, delicious, Doritoey crust that layered his genetically rippled fingertips? But then again, J. Edgar Hoover would want his pantyhose intertwined within the equation. However, I digress, momentarily. But Einstein gave freely, for humanity, not for gain, other than personal freedom. An equation that benefited all, and yet gain is a personal product. Also, if you can answer it, is gravity anymore than interplanetary static cling? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] RE: Organisational question: surely someone has implemented many Boolean values (tags) and a solution exist
>-Original Message- >From: Dotan Cohen [mailto:dotanco...@gmail.com] >Sent: Thursday, January 20, 2011 11:25 AM >To: Jerry Schwartz >Cc: mysql.; php-general. >Subject: Re: Organisational question: surely someone has implemented many >Boolean values (tags) and a solution exist > > >> As for setting up a hierarchy, that's trickier. One way to handle that is >> to >> work like libraries do: 10 is "fiction", 10.05 is "crime novels", 10.05.07 >> is >> "British authors", and so forth. Your `tags` table then looks like >> > >Thanks. I prefer the "parent tag" field, though, I feel that it is >more flexible. > > [JS] I disagree. The method I proposed can be extended to any depth, and any leaf or branch can be retrieved with a single query. Regards, Jerry Schwartz Global Information Incorporated 195 Farmington Ave. Farmington, CT 06032 860.674.8796 / FAX: 860.674.8341 E-mail: je...@gii.co.jp Web site: www.the-infoshop.com >-- >Dotan Cohen > >http://gibberish.co.il >http://what-is-what.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Organisational question: surely someone has implemented many Boolean values (tags) and a solution exist
On Thu, Jan 20, 2011 at 2:26 PM, Dotan Cohen wrote: > On Thu, Jan 20, 2011 at 21:24, David Hutto wrote: >>> Is this a troll? Am I about to be baited? >> >> Baited to deploy what is designed to the consumer's specification? >> Surely. From what is wanted to what is needed. Troll on that. > > Actually, I'm the customer! But assuming that a customer exists, that > implies compensation, and therefore fair bait. Then that's different altogether. you get to decide what information is displayed, and what information is 'sensed', and on what platform. What do you want to sense and what do you want to display(not to say I'm an expert, but I like to think in CS)? > > -- > Dotan Cohen > > http://gibberish.co.il > http://what-is-what.com > -- The lawyer in me says argue...even if you're wrong. The scientist in me... says shut up, listen, and then argue. But the lawyer won on appeal, so now I have to argue due to a court order. Furthermore, if you could be a scientific celebrity, would you want einstein sitting around with you on saturday morning, while you're sitting in your undies, watching Underdog?...Or better yet, would Einstein want you to violate his Underdog time? Can you imagine Einstein sitting around in his underware? Thinking about the relativity between his pubic nardsac, and his Fruit of the Looms, while knocking a few Dorito's crumbs off his inner brilliant white thighs, and hailing E = mc**2, and licking the orangy, delicious, Doritoey crust that layered his genetically rippled fingertips? But then again, J. Edgar Hoover would want his pantyhose intertwined within the equation. However, I digress, momentarily. But Einstein gave freely, for humanity, not for gain, other than personal freedom. An equation that benefited all, and yet gain is a personal product. Also, if you can answer it, is gravity anymore than interplanetary static cling? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Organisational question: surely someone has implemented many Boolean values (tags) and a solution exist
On Thu, Jan 20, 2011 at 21:24, David Hutto wrote: >> Is this a troll? Am I about to be baited? > > Baited to deploy what is designed to the consumer's specification? > Surely. From what is wanted to what is needed. Troll on that. Actually, I'm the customer! But assuming that a customer exists, that implies compensation, and therefore fair bait. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Organisational question: surely someone has implemented many Boolean values (tags) and a solution exist
> Is this a troll? Am I about to be baited? Baited to deploy what is designed to the consumer's specification? Surely. From what is wanted to what is needed. Troll on that. > > -- > Dotan Cohen > > http://gibberish.co.il > http://what-is-what.com > -- The lawyer in me says argue...even if you're wrong. The scientist in me... says shut up, listen, and then argue. But the lawyer won on appeal, so now I have to argue due to a court order. Furthermore, if you could be a scientific celebrity, would you want einstein sitting around with you on saturday morning, while you're sitting in your undies, watching Underdog?...Or better yet, would Einstein want you to violate his Underdog time? Can you imagine Einstein sitting around in his underware? Thinking about the relativity between his pubic nardsac, and his Fruit of the Looms, while knocking a few Dorito's crumbs off his inner brilliant white thighs, and hailing E = mc**2, and licking the orangy, delicious, Doritoey crust that layered his genetically rippled fingertips? But then again, J. Edgar Hoover would want his pantyhose intertwined within the equation. However, I digress, momentarily. But Einstein gave freely, for humanity, not for gain, other than personal freedom. An equation that benefited all, and yet gain is a personal product. Also, if you can answer it, is gravity anymore than interplanetary static cling? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: News Server Time Outs
On 01/19/2011 10:09 AM, Al wrote: > The newsgroup server seems to have a repeated-visit throttle, or whatever. > > For the last two weeks at least, I can only open 2 or 3 messages and > them I get repeated time-outs. It acts like the DoS or flood prevention > is kidding in to aggressively. > > Al.. Yesterday I couldn't connect at all, all day. Today it seems to be working OK. -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Organisational question: surely someone has implemented many Boolean values (tags) and a solution exist
On Thu, Jan 20, 2011 at 20:50, David Hutto wrote: > Pseudo = Design Algorithm > Design Algorithm = Actual Code > Actual Code = Alterable db tables > Alterable db tables = manipulated data through the app interface with data > > -- > The lawyer in me says argue...even if you're wrong. The scientist in > me... says shut up, listen, and then argue. But the lawyer won on > appeal, so now I have to argue due to a court order. > > Furthermore, if you could be a scientific celebrity, would you want > einstein sitting around with you on saturday morning, while you're > sitting in your undies, watching Underdog?...Or better yet, would > Einstein want you to violate his Underdog time? > > Can you imagine Einstein sitting around in his underware? Thinking > about the relativity between his pubic nardsac, and his Fruit of the > Looms, while knocking a few Dorito's crumbs off his inner brilliant > white thighs, and hailing E = mc**2, and licking the orangy, > delicious, Doritoey crust that layered his genetically rippled > fingertips? > > But then again, J. Edgar Hoover would want his pantyhose intertwined > within the equation. > > However, I digress, momentarily. > > But Einstein gave freely, for humanity, not for gain, other than > personal freedom. > > An equation that benefited all, and yet gain is a personal product. > > Also, if you can answer it, is gravity anymore than interplanetary static > cling? > Is this a troll? Am I about to be baited? -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Organisational question: surely someone has implemented many Boolean values (tags) and a solution exist
On Thu, Jan 20, 2011 at 19:21, Richard Quadling wrote: >> That is terrific, at least the first half. The second half, with the >> Venn diagrams, is awkward! > > When you get heavily nested data, the adjacent set model (where you > have a parentid for every uniqueid), you very quickly get into > complicated logic trying to traverse n-levels. The nested set model is > specifically built to handle this issue. I'd recommend getting to > grips with it. It will make finding items belonging to a group (or a > super group) a LOT easier. > > Especially if you have multiple tag hierarchies. > Is that strategy widely deployed, then? It seems so unruly having to change on average half the database records for every new leaf. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Organisational question: surely someone has implemented many Boolean values (tags) and a solution exist
Pseudo = Design Algorithm Design Algorithm = Actual Code Actual Code = Alterable db tables Alterable db tables = manipulated data through the app interface with data -- The lawyer in me says argue...even if you're wrong. The scientist in me... says shut up, listen, and then argue. But the lawyer won on appeal, so now I have to argue due to a court order. Furthermore, if you could be a scientific celebrity, would you want einstein sitting around with you on saturday morning, while you're sitting in your undies, watching Underdog?...Or better yet, would Einstein want you to violate his Underdog time? Can you imagine Einstein sitting around in his underware? Thinking about the relativity between his pubic nardsac, and his Fruit of the Looms, while knocking a few Dorito's crumbs off his inner brilliant white thighs, and hailing E = mc**2, and licking the orangy, delicious, Doritoey crust that layered his genetically rippled fingertips? But then again, J. Edgar Hoover would want his pantyhose intertwined within the equation. However, I digress, momentarily. But Einstein gave freely, for humanity, not for gain, other than personal freedom. An equation that benefited all, and yet gain is a personal product. Also, if you can answer it, is gravity anymore than interplanetary static cling? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Class and interface location
Larry, I suggested the docblock tag because it seemed you didn't want to mandate that plugins that extend other plugins be forced to include the interface in an actual PHP implements clause. Duplicating the implements clause doesn't cause any problems for PHP as you said, so that's one route. Advantages: Validated at runtime by the PHP compiler when the plugin is loaded. Disadvantages: If they forget to add the implements, their plugin won't be loaded. Then there's the docblock tag idea. Advantages: Easy to grab using grep. Disadvantages: If they forget to add the tag, their plugin won't be loaded. Someone mentioned creating a manifest file. If the plugins require any other configuration, this is a great place for it. Advantages: Easy to process. Disadvantages: If they forget to add an interface, their plugin won't receive its events but it will be "loaded" (not the class but the manifest). No matter which method you choose, you can make the plugin developer's life easier by writing a small script to validate the plugin and report which events it will receive. David
Re: [PHP] Organisational question: surely someone has implemented many Boolean values (tags) and a solution exist
I cannot agree more with the others about using a join table. While it's tempting to go with your first solution due to fear of performance issues, you can usually address performance issues with a technical solution. Addressing problems that arise from a constraining design choice is much more difficult. David
Re: [PHP] email address syntax checker
Nilesh Govindarajan wrote: On 01/20/2011 09:44 AM, Donovan Brooke wrote: Hi Guys, I'm waddling my way through database interaction and thought someone on the list may already have a simple email checker that they'd like to share... you know, looking for the @ char and dots etc.. I did a quick search of the archives and found a couple elaborate things.. but I'm looking for something simple. This job will have trusted users and the checker is more to help them catch mistakes when registering. Thanks!, Donovan Well, I had created an email validator long ago, after a neat research on Google, reading RFCs, etc. I don't guarantee that it's without bugs, but it has been correct for me in all valid & invalid email addresses I used for test. Code: 2) { return false; } list($username, $domain) = $split; /* * Don't allow * Two dots, Two @ * !, #, $, ^, &, *, (, ), [, ], {, }, ?, /, \, ~, `, <, >, ', " */ $userNameRegex1 = '/\.{2,}|@{2,}|[\!#\$\^&\*\(\)\[\]{}\?\/\\\|~`<>\'"]+/'; /* * Username should consist of only * A-Z, a-z, 0-9, -, ., _, +, % */ $userNameRegex2 = '/[a-z0-9_.+%-]+/i'; /* * Domain cannot contain two successive dots */ $domainRegex1 = '/\.{2,}/'; /* * Domain can contain only * A-Z, a-z, 0-9, ., -, */ $domainRegex2 = '/[a-z0-9.-]+/i'; if(preg_match($userNameRegex1, $username) or !preg_match($userNameRegex2, $username) or preg_match($domainRegex1, $domain) or !preg_match($domainRegex2, $domain) or !checkdnsrr($domain, 'MX')) { return false; } else { return true; } } Thanks! I think I'll go w/ Peter's suggestion for this site, but will take note of this for reference's sake! Cheers, Donovan -- D Brooke -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] email address syntax checker
Peter Lind wrote: [snip] if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { echo "Bad user! Bad user!"; } Regards Peter thanks peter... wish I would have known about filter_var before writing the other checkers. ;-) Donovan -- D Brooke -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Organisational question: surely someone has implemented many Boolean values (tags) and a solution exist
On 20 January 2011 16:20, Dotan Cohen wrote: > On Thu, Jan 20, 2011 at 17:00, Richard Quadling wrote: >> I'd have my items table, my tags table and a join table for the two. >> My join table is really simple. UniqueID, ItemID, TagID. >> > > Yes, that is the first approach that I mentioned. It looks to be a > good compromise. > > >> I'd recommend using a nested set approach for the tags >> (http://dev.mysql.com/tech-resources/articles/hierarchical-data.html >> gives a good explanation on the issues and methodology of nested >> sets). >> > > That is terrific, at least the first half. The second half, with the > Venn diagrams, is awkward! > > -- > Dotan Cohen > > http://gibberish.co.il > http://what-is-what.com > When you get heavily nested data, the adjacent set model (where you have a parentid for every uniqueid), you very quickly get into complicated logic trying to traverse n-levels. The nested set model is specifically built to handle this issue. I'd recommend getting to grips with it. It will make finding items belonging to a group (or a super group) a LOT easier. Especially if you have multiple tag hierarchies. -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Organisational question: surely someone has implemented many Boolean values (tags) and a solution exist
On Thu, Jan 20, 2011 at 17:22, Jerry Schwartz wrote: > I think the canonical way would be to have one table for your items, one table > for your tags, and one table for your tag assignments. > Thank you, I do agree that this is the best way. Other posters seem to agree as well! > Using an ever-lengthening bitmap for the tag assignments is a trap for the > unwary. The path to perdition is lined with the bodies of those who believed > "We'll never need more than x..." > 640 kb? > As for setting up a hierarchy, that's trickier. One way to handle that is to > work like libraries do: 10 is "fiction", 10.05 is "crime novels", 10.05.07 is > "British authors", and so forth. Your `tags` table then looks like > Thanks. I prefer the "parent tag" field, though, I feel that it is more flexible. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Organisational question: surely someone has implemented many Boolean values (tags) and a solution exist
On Thu, Jan 20, 2011 at 18:20, Dotan Cohen wrote: > On Thu, Jan 20, 2011 at 17:00, Richard Quadling wrote: >> I'd have my items table, my tags table and a join table for the two. >> My join table is really simple. UniqueID, ItemID, TagID. >> > > Yes, that is the first approach that I mentioned. It looks to be a > good compromise. > > Sorry, that was _not_ the first approach that I mentioned. It looks to be the right method though, thanks! -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Organisational question: surely someone has implemented many Boolean values (tags) and a solution exist
On Thu, Jan 20, 2011 at 17:00, Richard Quadling wrote: > I'd have my items table, my tags table and a join table for the two. > My join table is really simple. UniqueID, ItemID, TagID. > Yes, that is the first approach that I mentioned. It looks to be a good compromise. > I'd recommend using a nested set approach for the tags > (http://dev.mysql.com/tech-resources/articles/hierarchical-data.html > gives a good explanation on the issues and methodology of nested > sets). > That is terrific, at least the first half. The second half, with the Venn diagrams, is awkward! -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] RE: Organisational question: surely someone has implemented many Boolean values (tags) and a solution exist
I think the canonical way would be to have one table for your items, one table for your tags, and one table for your tag assignments. CREATE TABLE items ( item_id INT(11) AUTO-INCREMENT PRIMARY KEY, item_name VARCHAR(100) NOT NULL KEY, ... ); CREATE TABLE tags ( tag_id INT(11) AUTO-INCREMENT PRIMARY KEY, tag_name VARCHAR(100) NOT NULL KEY, ... ); CREATE TABLE item_tags ( item_id INT(11) NOT NULL KEY, tag_id INT(11) NOT NULL KEY ); This way you could do SELECT item_id, item_name FROM tags JOIN item_tags ON tags.tag_id = item_tags.tag_id JOIN items ON item_tags.item_id = items.item_id WHERE ... ; to get all of the items with a particular tag, or SELECT tag_id, tag_name FROM items JOIN item_tags ON items.item_id = item_tags.item_id JOIN tags ON item_tags.tag_id = tags.tag_id WHERE ... ; with equal ease and efficiency. Using an ever-lengthening bitmap for the tag assignments is a trap for the unwary. The path to perdition is lined with the bodies of those who believed "We'll never need more than x..." As for setting up a hierarchy, that's trickier. One way to handle that is to work like libraries do: 10 is "fiction", 10.05 is "crime novels", 10.05.07 is "British authors", and so forth. Your `tags` table then looks like CREATE TABLE tags ( tag_id INT(11) AUTO-INCREMENT PRIMARY KEY, tag_name VARCHAR(100) NOT NULL KEY, tag_number VARCHAR(100) NOT NULL KEY, ... ); Then you can search for tags by tag_number LIKE ('10.%') or tag_number LIKE ('10.05%') and so forth. This scheme is infinitely extendable. To get the entire hierarchy, you simply SELECT tag_number, tag_name FROM tags ORDER BY tag_number; Regards, Jerry Schwartz Global Information Incorporated 195 Farmington Ave. Farmington, CT 06032 860.674.8796 / FAX: 860.674.8341 E-mail: je...@gii.co.jp Web site: www.the-infoshop.com >-Original Message- >From: Dotan Cohen [mailto:dotanco...@gmail.com] >Sent: Thursday, January 20, 2011 9:32 AM >To: mysql.; php-general. >Subject: Organisational question: surely someone has implemented many Boolean >values (tags) and a solution exist > >I am designing an application that make heavy usage of one-to-many >tags for items. That is, each item can have multiple tags, and there >are tens of tags (likely to grow to hundreds). Most operation on the >database are expected to be searches for the items that have a >particular tag. That is, users will search per tags, not per items. > >These are the ways that I've thought about storing the tags, some bad >and some worse. If there is a better way I'd love to know. > >1) Each item will get a row in a "tags" table, with a column for each tag. >mysql> CREATE TABLE tags ( >id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, >item VARCHAR(100), >tag1 bool, >tag2 bool, > >tagN bool >); > >With this approach I would be adding a new column every time a new >category is added. This looks to me a good way given that users will >be searching per tag and a simple "SELECT item FROM tags WHERE >tag1=true;" is an easy, inexpensive query. This table will get very >large, there will likely be literally thousands of items (there will >exist more items than tags). > > > >2) Store the applicable tags one per line in a text field in the items table. >mysql> CREATE TABLE items ( >id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, >item VARCHAR(100), >tags text, >); > >This looks like a bad idea, searching by tag will be a mess. > > > >3) Store the tags in a table and add items to a text field. For instance: >mysql> CREATE TABLE tags ( >id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, >tagName VARCHAR(100), >items text, >); > >This looks to be the best way from a MySQL data retrieval perspective, >but I do not know how expensive it will be to then split the items in >PHP. Furthermore, adding items to tags could get real expensive. > > > >Caveat: at some point in the future there may be added the ability to >have a tag hierarchy. For instance, there could exist a tag >"restaurant" that will get the subtags "italian" and "french". I could >fake this with any approach by having a table of existing tags with a >"parentTag" field, so if I plan on having this table anyway would >method 3 above be preferable? > >Note: this message is cross-posted to the MySQL and the PHP lists as I >am really not sure where is the best place to do the logic. My >apologies to those who receive the message twice. > >Thanks! > >-- >Dotan Cohen > >http://gibberish.co.il >http://what-is-what.com > >-- >MySQL General Mailing List >For list archives: http://lists.mysql.com/mysql >To unsubscribe:http://lists.mysql.com/mysql?unsub=je...@gii.co.jp -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Organisational question: surely someone has implemented many Boolean values (tags) and a solution exist
On 20 January 2011 14:32, Dotan Cohen wrote: > I am designing an application that make heavy usage of one-to-many > tags for items. That is, each item can have multiple tags, and there > are tens of tags (likely to grow to hundreds). Most operation on the > database are expected to be searches for the items that have a > particular tag. That is, users will search per tags, not per items. > > These are the ways that I've thought about storing the tags, some bad > and some worse. If there is a better way I'd love to know. > > 1) Each item will get a row in a "tags" table, with a column for each tag. > mysql> CREATE TABLE tags ( > id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, > item VARCHAR(100), > tag1 bool, > tag2 bool, > > tagN bool > ); > > With this approach I would be adding a new column every time a new > category is added. This looks to me a good way given that users will > be searching per tag and a simple "SELECT item FROM tags WHERE > tag1=true;" is an easy, inexpensive query. This table will get very > large, there will likely be literally thousands of items (there will > exist more items than tags). > > > > 2) Store the applicable tags one per line in a text field in the items table. > mysql> CREATE TABLE items ( > id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, > item VARCHAR(100), > tags text, > ); > > This looks like a bad idea, searching by tag will be a mess. > > > > 3) Store the tags in a table and add items to a text field. For instance: > mysql> CREATE TABLE tags ( > id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, > tagName VARCHAR(100), > items text, > ); > > This looks to be the best way from a MySQL data retrieval perspective, > but I do not know how expensive it will be to then split the items in > PHP. Furthermore, adding items to tags could get real expensive. > > > > Caveat: at some point in the future there may be added the ability to > have a tag hierarchy. For instance, there could exist a tag > "restaurant" that will get the subtags "italian" and "french". I could > fake this with any approach by having a table of existing tags with a > "parentTag" field, so if I plan on having this table anyway would > method 3 above be preferable? > > Note: this message is cross-posted to the MySQL and the PHP lists as I > am really not sure where is the best place to do the logic. My > apologies to those who receive the message twice. > > Thanks! > > -- > Dotan Cohen > > http://gibberish.co.il > http://what-is-what.com > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > I'd have my items table, my tags table and a join table for the two. My join table is really simple. UniqueID, ItemID, TagID. I'd recommend using a nested set approach for the tags (http://dev.mysql.com/tech-resources/articles/hierarchical-data.html gives a good explanation on the issues and methodology of nested sets). -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Class and interface location
> -Original Message- > From: Steve Staples [mailto:sstap...@mnsi.net] > Sent: Thursday, January 20, 2011 5:16 AM > To: Larry Garfield > Cc: php-general@lists.php.net > Subject: Re: [PHP] Class and interface location > > On Wed, 2011-01-19 at 21:46 -0600, Larry Garfield wrote: > > On Wednesday, January 19, 2011 8:56:50 pm Tommy Pham wrote: > > > > > > And actually, thinking about it, I wonder if requiring the > > > > explicit > > > declaration > > > > is a good thing anyway because then it's immediately obvious and > > > > greppable what the class does. :-) > > > > > > > > --Larry Garfield > > > > > > You mean requiring explicit declaration of > > > > > > > class Bob implements Foo { > > > > > > > > } > > > > > > It's so you can guarantee your app from future breakage because the > > > interface guarantees minimum functionality and still maintain great > > > flexibility such that: > > > > Well, let me offer a more precise example of what I want to do: > > > > interface Stuff { > > function doStuff($a); > > } > > > > interface Things extends Stuff { > > function doThings($a); > > } > > > > class Bob implements Stuff {...} > > > > class Alice implements Stuff {...} > > > > class George {} > > > > class Matt implements Things {...} > > > > > > function make_stuff_happen($o) { > > foreach (class_that_implements_stuff() as $class) { > > $c = new $class(); > > $c->doStuff($o); > > } > > } > > > > The above code should iterate over Bob, Alice, and Matt, but not > > George. The trick is how to implement class_that_implements_stuff() > > (or rather, > > class_that_implements_something('Stuff')) in a sane and performant > > fashion that supports auto-loading. > > > > If all of the above is together in a single file, it's dead simple > > with > > get_declared_classes() and class_implements(). However, in practice > > there could be some 200 interfaces -- with each installation having a > > different set of them -- and as many as 500 classes implementing some > > combination of those interfaces, possibly multiple on the same class > > -- also with each installation having a different set of them. I do > > not want to be forced to include all of those classes and interfaces > > on every page load when in practice only perhaps two dozen will be > > needed on a particular request. That makes > > class_that_implements_stuff() considerably tricker. > > > > That let naturally to having a cached index (in a database, in a file > > with a big lookup array, whatever) that pre-computed which class > > implements what interface and what file it lives in, so that we can > > easily lookup what classes we need and then let the autoloader find > > them. (Previous benchmarks have shown that an index-based autoloader > > is actually pretty darned fast.) That just makes building that index the > challenge, hence this email thread. > > > > Thinking it through, however, I am now wondering if, in practice, > > indirect implementation (class Matt above) will even be that common. > > It may not be common enough to be an issue in practice, so requiring Matt > to be declared as: > > > > class Matt implements Stuff, Things {...} > > > > isn't really that big of a deal and makes the indexer considerably simpler. > > We actually have one already that indexes class locations; it just > > doesn't track interfaces. > > > > I also, on further review, don't think that class-based inheritance > > will ever be an issue. The following: > > > > class Mary extends Alice {...} > > > > Would not make much sense at all because then both Mary and Alice > > would run, so Alice's code would run twice. So I may be over-complicating > the situation. > > > > (For those following along at home, yes, this is essentially observer > pattern. > > However, it's on a very large scale and the thing being observed may > > not always be an object, so the usual active registration process of > > instantiating both objects and telling them about each other on the > > off chance that they > > *may* be needed is excessively wasteful.) > > > > Does that make it clearer what I'm trying to do? > > > > --Larry Garfield > > > > Maybe it's the noob in me, or the lack of smrts... but couldn't you just add a > var in the class, and set it like: > $GLOBALS['classes_that_do_things']['name'] = 'class_name'; And for those > that do 'things', and then do the foreach on that? > foreach($GLOBALS['classes_that_do_things']['name'] as $class_name) {...} > > not sure if that would work or not, it was just something that was in the > cobwebs of my brain this morning. > > Steve > @Steve, That would mean that class have to be either loaded/invoked. Larry doesn't want that. He wants a way to include the right class and instantiate it. " the usual active registration process of instantiating both objects and telling them about each other on the off chance that they *may* be needed is excessively wasteful" You wouldn't see the performance difference when yo
Re: [PHP] email address syntax checker
On 01/20/2011 09:44 AM, Donovan Brooke wrote: Hi Guys, I'm waddling my way through database interaction and thought someone on the list may already have a simple email checker that they'd like to share... you know, looking for the @ char and dots etc.. I did a quick search of the archives and found a couple elaborate things.. but I'm looking for something simple. This job will have trusted users and the checker is more to help them catch mistakes when registering. Thanks!, Donovan Well, I had created an email validator long ago, after a neat research on Google, reading RFCs, etc. I don't guarantee that it's without bugs, but it has been correct for me in all valid & invalid email addresses I used for test. Code: 2) { return false; } list($username, $domain) = $split; /* * Don't allow * Two dots, Two @ * !, #, $, ^, &, *, (, ), [, ], {, }, ?, /, \, ~, `, <, >, ', " */ $userNameRegex1 = '/\.{2,}|@{2,}|[\!#\$\^&\*\(\)\[\]{}\?\/\\\|~`<>\'"]+/'; /* * Username should consist of only * A-Z, a-z, 0-9, -, ., _, +, % */ $userNameRegex2 = '/[a-z0-9_.+%-]+/i'; /* * Domain cannot contain two successive dots */ $domainRegex1 = '/\.{2,}/'; /* * Domain can contain only * A-Z, a-z, 0-9, ., -, */ $domainRegex2 = '/[a-z0-9.-]+/i'; if(preg_match($userNameRegex1, $username) or !preg_match($userNameRegex2, $username) or preg_match($domainRegex1, $domain) or !preg_match($domainRegex2, $domain) or !checkdnsrr($domain, 'MX')) { return false; } else { return true; } } -- Regards, Nilesh Govindarajan Facebook: http://www.facebook.com/nilesh.gr Twitter: http://twitter.com/nileshgr Website: http://www.itech7.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Class and interface location
On Wed, 2011-01-19 at 21:46 -0600, Larry Garfield wrote: > On Wednesday, January 19, 2011 8:56:50 pm Tommy Pham wrote: > > > > And actually, thinking about it, I wonder if requiring the explicit > > declaration > > > is a good thing anyway because then it's immediately obvious and > > > greppable what the class does. :-) > > > > > > --Larry Garfield > > > > You mean requiring explicit declaration of > > > > > class Bob implements Foo { > > > > > > } > > > > It's so you can guarantee your app from future breakage because the > > interface guarantees minimum functionality and still maintain great > > flexibility such that: > > Well, let me offer a more precise example of what I want to do: > > interface Stuff { > function doStuff($a); > } > > interface Things extends Stuff { > function doThings($a); > } > > class Bob implements Stuff {...} > > class Alice implements Stuff {...} > > class George {} > > class Matt implements Things {...} > > > function make_stuff_happen($o) { > foreach (class_that_implements_stuff() as $class) { > $c = new $class(); > $c->doStuff($o); > } > } > > The above code should iterate over Bob, Alice, and Matt, but not George. The > trick is how to implement class_that_implements_stuff() (or rather, > class_that_implements_something('Stuff')) in a sane and performant fashion > that supports auto-loading. > > If all of the above is together in a single file, it's dead simple with > get_declared_classes() and class_implements(). However, in practice there > could be some 200 interfaces -- with each installation having a different set > of them -- and as many as 500 classes implementing some combination of those > interfaces, possibly multiple on the same class -- also with each > installation > having a different set of them. I do not want to be forced to include all of > those classes and interfaces on every page load when in practice only perhaps > two dozen will be needed on a particular request. That makes > class_that_implements_stuff() considerably tricker. > > That let naturally to having a cached index (in a database, in a file with a > big lookup array, whatever) that pre-computed which class implements what > interface and what file it lives in, so that we can easily lookup what > classes > we need and then let the autoloader find them. (Previous benchmarks have > shown that an index-based autoloader is actually pretty darned fast.) That > just makes building that index the challenge, hence this email thread. > > Thinking it through, however, I am now wondering if, in practice, indirect > implementation (class Matt above) will even be that common. It may not be > common enough to be an issue in practice, so requiring Matt to be declared as: > > class Matt implements Stuff, Things {...} > > isn't really that big of a deal and makes the indexer considerably simpler. > We actually have one already that indexes class locations; it just doesn't > track interfaces. > > I also, on further review, don't think that class-based inheritance will ever > be an issue. The following: > > class Mary extends Alice {...} > > Would not make much sense at all because then both Mary and Alice would run, > so Alice's code would run twice. So I may be over-complicating the situation. > > (For those following along at home, yes, this is essentially observer > pattern. > However, it's on a very large scale and the thing being observed may not > always be an object, so the usual active registration process of > instantiating > both objects and telling them about each other on the off chance that they > *may* be needed is excessively wasteful.) > > Does that make it clearer what I'm trying to do? > > --Larry Garfield > Maybe it's the noob in me, or the lack of smrts... but couldn't you just add a var in the class, and set it like: $GLOBALS['classes_that_do_things']['name'] = 'class_name'; And for those that do 'things', and then do the foreach on that? foreach($GLOBALS['classes_that_do_things']['name'] as $class_name) {...} not sure if that would work or not, it was just something that was in the cobwebs of my brain this morning. Steve -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Class and interface location
On 20 January 2011 03:46, Larry Garfield wrote: > Does that make it clearer what I'm trying to do? Some ideas. I've no idea if any of them are any good. 1 - All plugins implement a self-registration mechanism. A analogy to this in the Windows world would be an ActiveX component. All ActiveX components implement a function which is callable by a component registration program (regsvr32.exe). During installation of the app, the component registration process detects the registration function and calls it to register the component. The function provides all the data required for registration. So, something like ... /** * Register plugin * * @return pluginRegistration */ final static public function abstractBasePlugin::registerPlugin(){ // Create and populate a pluginRegistration object. // This would contain the interfaces implemented, the classes from which the get_called_class() extends along with the hierarchy of the interfaces and classes. } for example, would allow any class that extends abstractBasePlugin, to be able to provide all the details about its class and interface hierarchy. Rather than just dropping files onto the server and hoping things all work, all plugins must be "installed". This installation procedure would then build the index at installation time for each plugin. Add to this an unregister mechanism for those dead plugins (or for plugins being upgraded) ... If plugins are in constant development, the index needs to be updated when the plugin is ready. Forcing an installation procedure would certainly help here I think as only the current plugin needs to be analysed and only once. I'd probably also add details about the author of the plugin, so in the event that the plugin is deleted (see auto tuning below), the alerting system could inform the developer or whatever you think is appropriate. 2 - Code protection. Rather than leaving the source code as is, the installation process could PHAR archive the files before placing it in the appropriate place. That way, the include file wouldn't be editable in the live environment ... maybe not good for the developers, but for users, installed plugins can't be edited (easily) and therefore the index should be consistent. 3 - Auto tuning. I would probably add a small amount of realtime tuning to the indexer in the event that a plugin is missing (someone deleted the file). The lack of the file sends an appropriate email alert detailing the missing file and indicates any orphaned subclasses and then tags the index to exclude the missing class from that point onwards. All dependent subclasses would also have to be tagged to exclude them from the index. If the pluginRegistration content includes contact details, you can include these in the alert. 4 - Plugin Inheritence. During installation, if a plugin extends another plugin, you could either throw an alert of some sort or have a mechanism that says the parent class is non-callable. If nothing else, you could at least report it and tell the developers that they need to sort this out. Again, the developer may be able to provide details of this in the pluginRegistration content (bool $parentCallable = true). Obviously, multiple extensions could report different values for parentCallable, so there would need to be some sort of guidelines and the installer should enforce them. The main thrust of this is that doing a static analysis is going to be expensive and really you only need to analyse the file once and an "installation" procedure would provide that time. It would be a step that is familiar with many users (at least desktop user). And I think it isn't too onerous on the developers. They only have to populate a single object and extend from a single abstract class (or class that has already extended from the abstract plugin class). I hope these ideas help in some way. Richard. -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php