Re: [PHP] Boolean type forced on string assignment inside if statement
2013/1/3 Marc Guay marc.g...@gmail.com: I received the message below addressed only to me, but I believe the group could benefit. It looks like the single pipe is a bitwise operator so you will get an integer as a result (and probably other weird things to discover when using it on non-numbers). http://php.net/manual/en/language.operators.bitwise.php -- Forwarded message -- From: Volmar Machado qi.vol...@gmail.com Date: 3 January 2013 12:42 Subject: Re: [PHP] Boolean type forced on string assignment inside if statement To: Marc Guay marc.g...@gmail.com My results in a simple test: ?php $a = true; $b = false; // either null, or 0 echo ('($a | $b))' . ($a | $b) . 'br'); //1 echo ('($a || $b))' . ($a || $b) . 'br'); //1 echo ('($b | $a)' . ($b | $a) . 'br'); //1 echo ('($b || $a)' . ($b || $a) . 'br'); //1 echo ('($a | $a)'. ($a | $a) . 'br'); //1 echo ('($a || $a)' . ($a || $a) . 'br'); //1 echo ('($b | $b)' . ($b | $b) . 'br'); //0 echo ('($b || $b)' . ($b || $b) . 'br'); //false(outputs nothing) ? The basic difference for another test, where conditions are both true are : ?php $a = 4; $b = 3; echo ('($a | $b))' . ($a | $b) . 'br'); //7 echo ('($a || $b))' . ($a || $b) . 'br'); //1 echo ('($b | $a)' . ($b | $a) . 'br'); //7 echo ('($b || $a)' . ($b || $a) . 'br'); //1 echo ('($a | $a)'. ($a | $a) . 'br'); //4 echo ('($a || $a)' . ($a || $a) . 'br'); //1 echo ('($b | $b)' . ($b | $b) . 'br'); //3 echo ('($b || $b)' . ($b || $b) . 'br'); //1 echo ('($a $b))' . ($a $b) . 'br'); //0 --- echo ('($a $b))' . ($a $b) . 'br'); //1 echo ('($b $a)' . ($b $a) . 'br'); //0 --- echo ('($b $a)' . ($b $a) . 'br'); //1 echo ('($a $a)'. ($a $a) . 'br'); //4 echo ('($a $a)' . ($a $a) . 'br'); //1 echo ('($b $b)' . ($b $b) . 'br'); //3 echo ('($b $b)' . ($b $b) . 'br'); //1 ? ?php $a = 2; $b = 3; echo ('($a | $b))' . ($a | $b) . 'br'); //3 echo ('($a || $b))' . ($a || $b) . 'br'); //1 echo ('($b | $a)' . ($b | $a) . 'br'); //3 echo ('($b || $a)' . ($b || $a) . 'br'); //1 echo ('($a | $a)'. ($a | $a) . 'br'); //2 echo ('($a || $a)' . ($a || $a) . 'br'); //1 echo ('($b | $b)' . ($b | $b) . 'br'); //3 echo ('($b || $b)' . ($b || $b) . 'br'); //1 echo ('($a $b))' . ($a $b) . 'br'); //2 echo ('($a $b))' . ($a $b) . 'br'); //1 echo ('($b $a)' . ($b $a) . 'br'); //2 - echo ('($b $a)' . ($b $a) . 'br'); //1 echo ('($a $a)'. ($a $a) . 'br'); //2 echo ('($a $a)' . ($a $a) . 'br'); //1 echo ('($b $b)' . ($b $b) . 'br'); //3 echo ('($b $b)' . ($b $b) . 'br'); //1 ? When the one of the operators were 2, the cases with returns 2 otherwise returns 0 (Or 1 when any operator is 1). And if the operators are 1 and 2, return 0 too. Its curious for me. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Boolean type forced on string assignment inside if statement
Based on what I learned. I create this simple sample that can occurs in a real world application. This simulate a system that needs to send a mail when a flag ($mail) is true, the system need to check if the category is passed with the flag to know the type of mail to send. Here is the results. ?php $mail = true; $mail_types = array(0,1,2,3,4,5,6,7,8,9,'A','B'); $print_it = ''; foreach($mail_types as $mail_type){ echo For $mail_type:br; if($mail $mail_type){ $print_it = 'email sent.br'; } else { $print_it = 'Mail type not defined!'; } if($mail $mail_type){ $print_it = ('email sent.br' != $print_it) ? 'Only email sent.br' : NULL; } else { $print_it = ('email sent.br' == $print_it) ? 'Only email sent.br' : NULL; } echo $print_it; } ? 2013/1/3 Andreas Perstinger andiper...@gmail.com: Volmar Machado qi.vol...@gmail.com wrote: When the one of the operators were 2, the cases with returns 2 otherwise returns 0 (Or 1 when any operator is 1). And if the operators are 1 and 2, return 0 too. Its curious for me. is the bitwise and operator. You have to look at the binary representation of the numbers to see what is happening: 2 decimal is 0010 binary 1 decimal is 0001 binary 2 1 == 0010 0001 == == 0 In your other examples you had 2 3 == 0010 0011 == 0010 == 2 and 4 3 == 0100 0011 == == 0 Does this help? Bye, Andreas -- 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
Fwd: Re: [PHP] Rest
-- Mensagem encaminhada -- De: Volmar Machado qi.vol...@gmail.com Data: 27/10/2012 17:07 Assunto: Re: [PHP] Rest Para: Matijn Woudt tijn...@gmail.com But if what you want to know, is how to works inside, google for PHPMaster.org REST PHP. They have a two part article about it, and is really good Em 27/10/2012 14:49, Matijn Woudt tijn...@gmail.com escreveu: On Sat, Oct 27, 2012 at 7:47 PM, Adam Tong adam.to...@gmail.com wrote: Hi, I need to develop a rest API.I want your feedback on how you develop rest apis. I don't want to use a heavy framework just for that, and I find url rewriting time consuming. Any suggestions? Thank you I'd suggest you google for PHP REST. It has plenty of information. There are even lightweight frameworks that do nothing more than providing REST API. And while URL rewriting may be time consuming, you could use a single rewrite that pushes all to PHP and you can do the rest in PHP. - Matijn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Programmers and developers needed
I guess that social structures didn't changed so much the last 10k years. I also guess if we want peace at all. The people just need to fight for something. Homogeneous world don't would bring heterogeneous ideas. Anyway I hope that you could do this, and become a great great genius, that will ever shine in the history and future generations. 2012/9/18 Matijn Woudt tijn...@gmail.com: On Tue, Sep 18, 2012 at 8:52 AM, agbo onyador onya...@gmail.com wrote: The growing power of the internet and global networks. (on the world's politics, economies and even on daily life of ordinary people) Programmers and developers needed: Thanks I still cannot figure out if this is a joke or if you're really looking for world peace.. If you're serious, you might want to stop and take a look at Newton's third law, I quote from wikipedia: When a first body exerts a force F1 on a second body, the second body simultaneously exerts a force F2 = -F1 on the first body. This means that F1 and F2 are equal in magnitude and opposite in direction., or simplified To every action there is always an equal and opposite reaction. It fits also easily on humans, take one step into peace, and it will have an effect in opposite direction elsewhere. Also, why do you think you can make a better social network than the already existing ones? Even the big internet giant Google can't seem to make it's social network a big success, and you (without even an concrete idea) can do that better? You might as well just open a simple website with a 'Like' button and ask everyone to like that page, so we end up with peace!:) - Matijn -- 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] Display Array Tree as Menu - Can't figure out how to find depth with something over 2 levels
http://www.php.net/manual/es/function.array-walk-recursive.php 2012/8/16 Tristan sunnrun...@gmail.com: I can't for the life of me figure out how to find the depth of the array that I'm looping through to output tabs or indentations to the display for each depth. The entries also have section postition if you can figure out how to include that within each depth of the results I will buy you a case of beer. I was hoping to do something like... foreach($trees as $tree){ if($tree['current_depth'] == 0){ echo $tree['menu_item']; } else if($tree['current_depth'] == 1){ echo 'indentation'.$tree['menu_item']; } else if($tree['current_depth'] == 2){ echo 'indentation - indentation'.$tree['menu_item']; } } Or maybe even like this... foreach($trees as $tree){ // output nbsp; the amount of times current_depth equals echo str_repeat(nbsp;, $tree['current_depth']) } I have my $tree structure as: [16] = Array ( [section_id] = 21 [section_parent_id] = 0 [section_pos] = 30 [section_name] = Resource Center [has_order] = 1 [section_has_hierarchy] = 1 [total_entries] = 35 [children] = Array ( [0] = Array ( [section_id] = 38 [section_parent_id] = 21 [section_pos] = 31 [section_name] = Resource Center [has_order] = 1 [section_has_hierarchy] = 1 [total_entries] = 35 [children] = Array ( [0] = Array ( [section_id] = 39 [section_parent_id] = 38 [section_pos] = 32 [section_name] = Resource Center [has_order] = 1 [section_has_hierarchy] = 1 [total_entries] = 35 ) [1] = Array ( [section_id] = 40 [section_parent_id] = 38 [section_pos] = 33 [section_name] = Resource Center [has_order] = 1 [section_has_hierarchy] = 1 [total_entries] = 35 ) ) [19] = Array ( [section_id] = 26 [section_parent_id] = 0 [section_pos] = 45 [section_name] = Resource Center [has_order] = 1 [section_has_hierarchy] = 1 [total_entries] = 55 [children] = Array ( [0] = Array ( [section_id] = 27 [section_parent_id] = 26 [section_pos] = 46 [section_name] = Newsletters Intro [has_order] = 0 [section_has_hierarchy] = 1 [total_entries] = 1 ) ) ) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Display Array Tree as Menu - Can't figure out how to find depth with something over 2 levels
I have develop a solution in a one function as in the example, which permit you to have n-level menu array, if you want you can change the returns by a echo to, if you want the ouput in html. http://pastebin.com/QJUsxPBw -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Reading class variable value always returns NULL
It's only a hint, but You start checking if the Object Ids are the same or not. 2012/8/13 Robert Cummings rob...@interjinn.com: On 12-08-12 08:32 AM, Reto Kaiser wrote: Hi, So I have this strange situation where I assign a classvariable a value, but when I read the value it is NULL. The class has one variable declared: = class A { private $_cookies; } = That is a private instance variable NOT a class variable. To declare a class variable you would do the following: ?php class A { private static $_cookies; } ? In a method of this class I assign this classvariable plus an undeclared classvariable and a local variable the value 1: = $this-_cookies = 1; $this-_cookies2 = 1; $cookies3 = 1; = When I now read the values of those variables, the classvariables are NULL while the local variable is 1: = $logEntry .= 'cookies: ' . var_export($this-_cookies, true) . PHP_EOL; $logEntry .= 'cookies2: ' . var_export($this-_cookies2, true) . PHP_EOL; $logEntry .= 'cookies3: ' . var_export($cookies3, true) . PHP_EOL; = cookies: NULL cookies2: NULL cookies3: 1 = But when reading the whole object, the classvariables are 1: = $logEntry .= var_export($this, true) . PHP_EOL; = A::__set_state(array( '_cookies' = 1, '_cookies2' = 1, )) = This happens periodically on a busy webserver. It seems that when it happens, all classvariables cannot be read anymore (return NULL). After restarting Apache it does not happen anymore, just to happen again after some minutes. The system is current Debian Squeeze: Linux: linux-image-2.6.32-5-amd64 Apache: apache2-mpm-prefork 2.2.16-6+squeeze7 PHP: PHP 5.3.3-7+squeeze13 with Suhosin-Patch (cli) (built: Jun 10 2012 07:31:32) php -m: https://raw.github.com/gist/3331641/2f7e80bd03abfb728b659634d3f4bac0131f4d6a/gistfile1.txt php -i: https://raw.github.com/gist/3331651/bcf6e3654bf391482627505447848de173d0bbab/gistfile1.txt Does anyone have an idea what could cause this, or how to further debug? I can't really speak to your specific problem (unless you're using two different instances of the class), just thought I'd clear up the difference between class variables and instance variables. Cheers, Rob. -- E-Mail Disclaimer: Information contained in this message and any attached documents is considered confidential and legally protected. This message is intended solely for the addressee(s). Disclosure, copying, and distribution are prohibited unless authorized. -- 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] Quem esta por dentro de PSR?
Sorry, I sent to wrong list :/ Em 10 de julho de 2012 11:05, Daniel Brown danbr...@php.net escreveu: 2012/7/10 Volmar Machado qi.vol...@gmail.com: Nao sei se sabem, mas tem uma galera implemantendo PSR-X, que sao padroes para desenvolvimento em PHP. Gostaria de saber o que pensam disso :) Eu não sei, mas não é realmente uma questão de PHP, e isso é realmente apenas uma lista de discussão Inglês. -- /Daniel P. Brown Network Infrastructure Manager http://www.php.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php