Re: [PHP] php string syntax question with html
$var = 'bla'.$var2.'doh'.$var3['index'].'argh'.$var4[$var4index]; is so much more readable in any editor that does syntax highlighting, and parses quicker too. On Thu, Mar 11, 2010 at 1:15 AM, David Mehler wrote: > Hello, > I've got what is probably a very simple question, probably something > having to do with quotes single vs. double, but the answer is > frustrating elusive, I keep getting a syntax error. > I'm trying to customize a wordpress theme a friend sent me. We're both > using apache as web server and php5, but his has got to be configed > differently than mine. The theme deals with multiple stylesheet > inclusion among other things. The original line is: > > $styleSheets[0]["sheet"]=' href="/wp-content/themes/theme/style/white.css" rel="stylesheet" > type="text/css" />'; > > That code puts the issue is his / is not where mine is, i'm using a virtual host and need > a line similar to this: > > $styleSheets[0]["sheet"]=' "/wp-content/themes/theme/style/white.css" rel="stylesheet" > type="text/css" />'; > > I've tried this with both double quotes before the but keep getting a parse error. > Help appreciated. > Thanks. > Dave. > > -- > 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] Execution order of PHP
You may not care about this, but from a readability perspective, i think relying on $client->system being as special as you describe, is not very readable. If i'd had to read code that does what you describe, i'd be much happier to see a datastructure be passed as was suggested elsewhere in this thread, but even more happy to see something like this: $client->system->specificMultiCall ( multiCallCommandCreate(array( 0 => array('function1', 'f1p1', f1p2'), 1 => array('function2', 'eval:f2p1', 'f2p2', 'f2p3'), 'f2p1' => array('function3', 'f3p1', 'f3p2') ) ); This structure allows for calling of any chain of methods, the array returned by multiCallCommandCreate() can be ordered, the root of this tree is the sequentially ordered integer keys, parameters are parsed left-to-right as usual. multiCallCommandCreate() can then set up an array for use by specificMultiCall(), the one returned by the collection routine for $client->system. The advantages of this are possibly some extra readability, but also some more room for expansion. On Wed, Mar 10, 2010 at 3:13 PM, Auke van Slooten wrote: > Bruno Fajardo wrote: >> >> 2010/3/10 Auke van Slooten >>> >>> Hi, >>> >>> In a hobby project I'm relying on the order in which the following piece >>> of PHP code is executed: >>> >>> $client->system->multiCall( >>> $client->methodOne(), >>> $client->methodTwo() >>> ); >> >> Can't you call the methods $client->methodOne() and >> $client->methodTwo() before the call to $client->system->multiCall()? >> That way, you could store they values in local variables, and then >> pass them to the $client->system->multiCall(), assuring that those >> methods are executed before the multiCall(). Something like: >> >> $methodOne = $client->methodOne(); >> $methodTwo = $client->methodTwo(); >> $client->system->multiCall($methodOne, $methodTwo); > > Hi, > > This is not what I meant. I should perhaps mention that it's an xml-rpc > client and the method calls are remote method calls. The multiCall method > gathers multiple method calls into a single request. > > The trick I'm using now is to set a private property in the $client->__get() > method when the property you're accessing is 'system'. From then untill you > call the method 'multiCall', instead of calling the methods (in this case > methodOne and methodTwo) the client creates a new object with the call > information (method name and arguments) and returns that. In multiCall all > arguments are therefor call information objects and multicall creates a > single request based on that information. > > So in your example the client would simply call methodOne and methodTwo and > return the results. Then it would try to do a multiCall with whatever the > previous methods have returned. > > regards, > Auke van Slooten > Muze > > -- > 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] Array Search Problem
(almost) all the tricks are in the comments of the help page for a function, on php.net but all functions accept only a given (and usually documented) set of parameter(type)s, so you'll probably have to prepare the var, or even call the function in a loop, outputting to yet another descriptively named array that'll be used as "wanted list" later in the code. On Wed, Mar 10, 2010 at 6:57 PM, Alice Wei wrote: >> >> did you read the help for those functions on php.net? > > Yes, I found a "recursive" way to find out the "index" like I wanted, by > doing something like > > $from = explode("-", $from); > $state_colors= explode("-", $state_colors); > $change = explode("-",$change); > > $count = count($new_array); > $i=0; > foreach ($new_array as $key => $value){ > echo $i . " " . $key . " is " . $value . " miles away"; > $i++; > } > > You can see it is not very elegant, and plus, I created the $new_array so I > could do the ordering according to the values of the change array. I can > tell that since this is not a single array, which is probably why > array_search does not work. > Since I don't need the "value" of my "new_array" here, I am still finding > out how to "strip off" the values here without having to flatten my array. > Is what I am trying to do here possible? Or, is there a trick in > array_search that I could use to find the index without having to strip off > anything? > > Thanks for your help. > > Alice > >> >> On Wed, Mar 10, 2010 at 4:12 PM, Alice Wei wrote: >> > >> > Hi, >> > >> > I have the code as shown in the following that I am trying to create >> > the image of based on the file loaded into the file and additional edits. >> > The problem here appears to be that no matter what value I have in the >> > $distance_to_destination variable, it does not affect any changes on the >> > map. What I am trying to do here is to create a map based on the pre-passed >> > through colors of individual states from another program, but I have to >> > match up the colors based on the values of the correct states. >> > >> > I figured that I may have problems with >> > >> > $key= array_search($location2,$from); //Find out the position of the >> > index in the array >> > >> > $colors_style = ";fill:" . $state_colors[$key]; //Use the index from >> > array_search to apply to the color index >> > >> > Obviously, it is not applying the colors to the states that I would like >> > other than doing it one by one as the order of what is in the $from >> > variable. Could someone please give me some hints on how I could do the >> > array_search here based on the "value" of the values in the >> > $distance_to_distance and apply the color to the states? >> > >> > > > >> > header("Content-type: image/svg+xml"); //Outputting an SVG >> > >> > $from = $_GET['from']; >> > $state_colors= $_GET['state_colors']; >> > $distance_to_destination= $_GET['distance_to_destination']; >> > >> > $from = explode("-", $from); >> > $state_colors= explode("-", $state_colors); >> > $change = explode("-",$change); >> > >> > #Load the Map >> > $ourFileName= "USA_Counties_with_FIPS_and_names.svg"; >> > $fh = fopen($ourFileName, "r") or die("Can't open file"); >> > $contents = fread($fh,filesize($ourFileName)); >> > $lines2= file($ourFileName); >> > >> > foreach ($lines2 as $line_num => $line2) { >> > >> > $style_line_num = $line_num+3; >> > $line2 = trim($line2); >> > >> > if(preg_match("/^style/",$line2)) { >> > >> > $rest = substr($line2,0,-1); >> > >> > for ($j=$line_num;$j<=$style_line_num;$j++){ >> > if(preg_match("/inkscape:label/",$lines2[$j])) { >> > $location = explode("=",$lines2[$j]); >> > $location2 = substr($location[1],1,-6); >> > >> > if(in_array($location2, $from)) { >> > >> > $key= array_search($location2,$from); //Find out the >> > position of the index in the array >> > $colors_style = ";fill:" . $state_colors[$key]; //Use the >> > index from array_search to apply to the color index >> > $rest2 = substr($line2,0,-1). $colors_style . "\""; >> > echo $rest2 . "\n"; >> > } >> > else echo $line2 . "\n"; >> > >> > } //end preg_match inkscape >> > } //end for loop >> > } //If preg_match style >> > >> > else echo $line2 . "\n"; //else if preg_match style >> > } //end for each >> > >> > fclose($fh); >> > ?> >> > >> > Thanks for your help. >> > >> > Alice >> > >> > _ >> > Hotmail: Trusted email with Microsoft’s powerful SPAM protection. >> > http://clk.atdmt.com/GBL/go/201469226/direct/01/ > > > Hotmail: Powerful Free email with security by Microsoft. Get it now. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Array Search Not Working?
On Wed, 10 Mar 2010 09:52:30 -0500, aj...@alumni.iu.edu (Alice Wei) wrote: > >Hi, > > I have two arrays here that I have combined into a new array, as shown here: > >$from = explode("-", $from); >$change = explode("-",$change); >$new_array = array_combine($from,$change); > >I then tried reading it from a file and do string matches, trying to find out >the "key" using the array_search of the individual array elements. I seem to >have no such luck, even when I copied one of the elements after I do a >print_r($new_array); > >Here is the code, > >foreach ($lines2 as $line_num => $line2) { >$style_line_num = $line_num+3; > > if(preg_match("/^style/",$line2)) { > >if(preg_match("/inkscape:label/",$lines2[$style_line_num])) { >$location = explode("=",$lines2[$style_line_num]); >$location2 = substr($patient_location[1],1,-6); > > if(in_array($location2, $from)) { > $key= array_search($location2,$new_array); //Find out the > position of the index in the array > echo "Key " . $key . ""; //This only gives me a blank space > after the word Key > >} > > } //end preg_match inkscape > } //If preg_match style > >I looked at the example from >http://php.net/manual/en/function.array-search.php, and looks like what I am >trying to do here is possible, and yet, why am I not getting a proper key >return? > >Thanks for your help. > >Alice I have a very handy utility for problems like this: // Expand string array, & list all terms function larec($array, $name) // List array recursive { if (is_array($array)) { $j = count ($array); $temp = array_keys($array); $i = 0; while ($i < $j) { if(isset($array[$temp[$i]])) { $new_line = $name."['".$temp[$i]."']"; larec ($array[$temp[$i]], $new_line); } $i++; } } else { echo ''.$name.' = '.$array.''; } } If you have some array $foo then larec($foo,'Foo'); will list all the elements of $foo recursively, without any obvious limits. This makes it very easy to see what you have actually got, as opposed to what you thought you would get. The following is an abridged example of the result of listing an array $wkg_sys of mine, using: larec ($wkg_sys,'Sys'); Sys['class'] = W Sys['style']['0']['wkg_style'] = basic_tab Sys['style']['0']['pad'] = Sys['style']['0']['stripe'] = 0 Sys['style']['1']['wkg_style'] = nrml_style Sys['style']['1']['pad'] = 1 Sys['style']['1']['stripe'] = 0 Sys['valid'] = 1 Sys['entries'] = 15 Sys['f_title'] = Developmental Web Page Sys['version'] = IF1.4 Sys['ident'] = 0800 Sys['directory_id'] = Sys['index'] = 2 Sys['date'] = CCY2N Clancy -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php string syntax question with html
On Thu, Mar 11, 2010 at 01:17:57AM +, Ashley Sheridan wrote: > > You're using single quotes in your string, so you can't have PHP parse > the string for variables to extend into their corresponding values. If > you wish to do that, use either double-quoted strings or heredoc/nowdoc > syntax: > > $styleSheets[0]["sheet"]=" \"{$_SERVER['DOCUMENT_ROOT']}/wp-content/themes/theme/style/white.css\" > rel=\"stylesheet\" type=\"text/css\" />"; > > or > > $styleSheets[0]["sheet"]= << href="{$_SERVER['DOCUMENT_ROOT']}/wp-content/themes/theme/style/white.css" > rel="stylesheet" type="text/css" /> > EOS; > > In both cases note the {} surrounding the variable. This is because PHP > needs to be told that you are trying to access an array element, > otherwise it will match only as far as $_SERVER and think that the > [ character starts regular text. This also works with object properties > and method return values: > > echo "{$some_obect->some_value} and {$some_object->some_method()}"; Um, not exactly. "This will parse correctly: $_SERVER[DOCUMENT_ROOT]." You just can't use single quotes inside the brackets to denote the array index, when the whole string is surrounded by double quotes. A more pedestrian example: $message = "The value of foo is $_POST[bar]\n"; You are, however, right about object properties. I know of no other way to parse them inside a quoted string, other than using braces. Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php string syntax question with html
On Wed, 2010-03-10 at 19:33 -0500, Adam Richardson wrote: > Try this: > > ' .'/wp-content/themes/themestyle/white.css" rel="stylesheet" type="text/css" > />'; > > On Wed, Mar 10, 2010 at 7:15 PM, David Mehler wrote: > > > Hello, > > I've got what is probably a very simple question, probably something > > having to do with quotes single vs. double, but the answer is > > frustrating elusive, I keep getting a syntax error. > > I'm trying to customize a wordpress theme a friend sent me. We're both > > using apache as web server and php5, but his has got to be configed > > differently than mine. The theme deals with multiple stylesheet > > inclusion among other things. The original line is: > > > > $styleSheets[0]["sheet"]=' > href="/wp-content/themes/theme/style/white.css" rel="stylesheet" > > type="text/css" />'; > > > > That code puts the > issue is his / is not where mine is, i'm using a virtual host and need > > a line similar to this: > > > > $styleSheets[0]["sheet"]=' > "/wp-content/themes/theme/style/white.css" rel="stylesheet" > > type="text/css" />'; > > > > I've tried this with both double quotes before the > but keep getting a parse error. > > Help appreciated. > > Thanks. > > Dave. > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > You're using single quotes in your string, so you can't have PHP parse the string for variables to extend into their corresponding values. If you wish to do that, use either double-quoted strings or heredoc/nowdoc syntax: $styleSheets[0]["sheet"]=""; or $styleSheets[0]["sheet"]= << EOS; In both cases note the {} surrounding the variable. This is because PHP needs to be told that you are trying to access an array element, otherwise it will match only as far as $_SERVER and think that the [ character starts regular text. This also works with object properties and method return values: echo "{$some_obect->some_value} and {$some_object->some_method()}"; Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] php string syntax question with html
Try this: ''; On Wed, Mar 10, 2010 at 7:15 PM, David Mehler wrote: > Hello, > I've got what is probably a very simple question, probably something > having to do with quotes single vs. double, but the answer is > frustrating elusive, I keep getting a syntax error. > I'm trying to customize a wordpress theme a friend sent me. We're both > using apache as web server and php5, but his has got to be configed > differently than mine. The theme deals with multiple stylesheet > inclusion among other things. The original line is: > > $styleSheets[0]["sheet"]=' href="/wp-content/themes/theme/style/white.css" rel="stylesheet" > type="text/css" />'; > > That code puts the issue is his / is not where mine is, i'm using a virtual host and need > a line similar to this: > > $styleSheets[0]["sheet"]=' "/wp-content/themes/theme/style/white.css" rel="stylesheet" > type="text/css" />'; > > I've tried this with both double quotes before the but keep getting a parse error. > Help appreciated. > Thanks. > Dave. > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Nephtali: PHP web framework that functions beautifully http://nephtaliproject.com
[PHP] php string syntax question with html
Hello, I've got what is probably a very simple question, probably something having to do with quotes single vs. double, but the answer is frustrating elusive, I keep getting a syntax error. I'm trying to customize a wordpress theme a friend sent me. We're both using apache as web server and php5, but his has got to be configed differently than mine. The theme deals with multiple stylesheet inclusion among other things. The original line is: $styleSheets[0]["sheet"]=''; That code puts the '; I've tried this with both double quotes before the http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Division by 0
On Wed, Mar 10, 2010 at 23:44, Dmitry Ruban wrote: > Hi Jochem, > > Jochem Maas wrote: >> >> Op 3/10/10 6:23 PM, Joseph Thayne schreef: >>> >>> Looks to me like you are closing your form before you put anything in >>> it. Therefore, the loan_amount is not set making the value 0. Follow >>> the math, and you are dividing by 1-1. >>> >>> Change this line: >>> >>> >>> >>> to: >>> >>> >> >> this is a XSS waiting to happen. I can put something like the following in >> the request uri: >> >> index.php?" onsubmit="evil()">> src="http://www.evil.com/evi.js";> >> > Apparently it's not going to work. PHP_SELF does not include query string. > So it is safe to use it this way. > > Regards, > Dmitry No, it is not safe... This won't work: index.php?" onsubmit="evil()">http://www.evil.com/evi.js";> But this will: index.php/" onsubmit="evil()">http://www.evil.com/evi.js";> -- Daniel Egeberg -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Division by 0
Hi Jochem, Jochem Maas wrote: Op 3/10/10 6:23 PM, Joseph Thayne schreef: Looks to me like you are closing your form before you put anything in it. Therefore, the loan_amount is not set making the value 0. Follow the math, and you are dividing by 1-1. Change this line: to: this is a XSS waiting to happen. I can put something like the following in the request uri: index.php?" onsubmit="evil()">http://www.evil.com/evi.js";> Apparently it's not going to work. PHP_SELF does not include query string. So it is safe to use it this way. Regards, Dmitry -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Division by 0
On Wed, Mar 10, 2010 at 22:27, Jochem Maas wrote: > Op 3/10/10 6:23 PM, Joseph Thayne schreef: >> Looks to me like you are closing your form before you put anything in >> it. Therefore, the loan_amount is not set making the value 0. Follow >> the math, and you are dividing by 1-1. >> >> Change this line: >> >> >> >> to: >> >> > > this is a XSS waiting to happen. I can put something like the following in > the request uri: > > index.php?" onsubmit="evil()"> src="http://www.evil.com/evi.js";> > > with regard to the original problem - some input validation is in order. PHP_SELF doesn't contain the query string, so your particular attack wouldn't work. It's still a security issue though. -- Daniel Egeberg -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Division by 0
Joseph My apologise for not writing sooner to thank you, you were of course correct. Thanks again. Gary "Joseph Thayne" wrote in message news:4b97e3a2.2030...@thaynefam.org... > Looks to me like you are closing your form before you put anything in it. > Therefore, the loan_amount is not set making the value 0. Follow the > math, and you are dividing by 1-1. > > Change this line: > > > > to: > > > > and you should be good to go. > > Joseph > > Gary wrote: >> I have a mortgage amortization script that was working fine,now it seems >> to have gone awry. Below is the entire script plus input page. I am >> getting an error >> >> Warning: Division by zero in >> /home/content/J/a/y/Jayski/html/one2one/Ricksrecursivefunctions.php on >> line 47 >> >> Which is (pow($intCalc,$totalPayments) - 1); >> >> Frankly I am not even sure the information is being passed to the script. >> >> Anyone see what I am missing? >> >> Gary >> >> >> Calculate your Loan >> >> >> >> >> >> Loan Amount >> USD >> > src="images/help.png" class="noborder"/> >> >> >> Type of >> Loan >> >> >> Installment >> Balloon >> >> > class="noborder"/> >> >> >> Term of Loan >> >> Months >> > src="images/help.png" class="noborder" /> >> >> >> Interest >> Rate >> Per >> Annum> /> >> >> >> >> >> >> >> > >> function amortizationTable($paymentNum, $periodicPayment, $balance, >>$monthlyInterest) { >> $paymentInterest = round($balance * $monthlyInterest,2); >> $paymentPrincipal = round($periodicPayment - $paymentInterest,2); >> $newBalance = round($balance - $paymentPrincipal,2); >> print " >>$paymentNum >>\$".number_format($balance,2)." >>\$".number_format($periodicPayment,2)." >>\$".number_format($paymentInterest,2)." >>\$".number_format($paymentPrincipal,2)." >>"; >> # If balance not yet zero, recursively call amortizationTable() >> if ($newBalance > 0) { >> $paymentNum++; >> amortizationTable($paymentNum, $periodicPayment, $newBalance, >> $monthlyInterest); >> } else { >> exit; >> } >> } #end amortizationTable() >> >># Loan balance >>$balance =($_POST['loan_amount']); >> >># Loan interest rate >>$interestRate = ($_POST['int_rate']); >> >># Monthly interest rate >>$monthlyInterest = ("$interestRate / 12"); >> >># Term length of the loan, in years. >>$termLength =($_POST['loan_term']); >> >># Number of payments per year. >>$paymentsPerYear = 12; >> >># Payment iteration >>$paymentNumber =($_POST['loan_term']); >> >># Perform preliminary calculations >>$totalPayments = $termLength * $paymentsPerYear; >>$intCalc = 1 + $interestRate / $paymentsPerYear; >>$periodicPayment = $balance * pow($intCalc,$totalPayments) * >> ($intCalc - 1) / >> (pow($intCalc,$totalPayments) - 1); >>$periodicPayment = round($periodicPayment,2); >> >># Create table >>echo ""; >>print " >> Payment >> NumberBalance >> PaymentInterestPrincipal >> "; >> >># Call recursive function >>amortizationTable($paymentNumber, $periodicPayment, $balance, >> $monthlyInterest); >> >># Close table >>print ""; >> >> ?> >> >> >> >> __ Information from ESET Smart Security, version of virus >> signature database 4932 (20100310) __ >> >> The message was checked by ESET Smart Security. >> >> http://www.eset.com >> >> >> >> >> >> > > __ Information from ESET Smart Security, version of virus > signature database 4932 (20100310) __ > > The message was checked by ESET Smart Security. > > http://www.eset.com > > > __ Information from ESET Smart Security, version of virus signature database 4933 (20100310) __ The message was checked by ESET Smart Security. http://www.eset.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Execution order of PHP
Op 3/10/10 1:29 PM, Auke van Slooten schreef: > Hi, > > In a hobby project I'm relying on the order in which the following piece > of PHP code is executed: > > $client->system->multiCall( > $client->methodOne(), > $client->methodTwo() > ); > > Currently PHP always resolves $client->system (and executes the __get on > $client) before resolving the arguments to the multiCall() method call. > > Is this order something that is specified by PHP and so can be relied > upon to stay the same in the future or is it just how it currently works. > > If it cannot be relied upon to stay this way, I will have to rewrite the > multiCall method and API... I think you can probably rely on the call order but given no formal spec for php it's not ironclad - multiCall() will never be called before methodOne() or methodTwo() because the return values of those are needed to pass to multiCall() BUT you can't say for sure whether $client->system will be evaluated before the methodOne() and methodTwo() calls ... looking at it the code doesn't actually require it, in practice it doubt the engine will change so dramatically that the call order would change. but who cares. the code is full of magic, which makes it difficult to understand and maintain ... fix it so that it's explicit about what it's doing so that other developers who read it will grasp the concept without having to dig into your magic methods. this solves the problem of undiscernable magic and possible issues with resolution order in the future as well (which if they happened would be a royal PITA to debug, given the magic methods involved) > > regards, > Auke van Slooten > Muze > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Division by 0
Op 3/10/10 6:23 PM, Joseph Thayne schreef: > Looks to me like you are closing your form before you put anything in > it. Therefore, the loan_amount is not set making the value 0. Follow > the math, and you are dividing by 1-1. > > Change this line: > > > > to: > > this is a XSS waiting to happen. I can put something like the following in the request uri: index.php?" onsubmit="evil()">http://www.evil.com/evi.js"</a>;> with regard to the original problem - some input validation is in order. (pow($intCalc,$totalPayments) - 1); if $intCal and $totalPayments are both equal to 1 then either something is wrong and the calc shouldn't be done or some other calc needs to be done. every value being POSTed should be checked that it's been set, and that it's a valid numeric value (for the numeric fields) ... if anything is missing show the form again and display an error message without doing the calculation. > > and you should be good to go. > > Joseph > > Gary wrote: >> I have a mortgage amortization script that was working fine,now it >> seems to have gone awry. Below is the entire script plus input page. >> I am getting an error >> >> Warning: Division by zero in >> /home/content/J/a/y/Jayski/html/one2one/Ricksrecursivefunctions.php on >> line 47 >> >> Which is (pow($intCalc,$totalPayments) - 1); >> >> Frankly I am not even sure the information is being passed to the script. >> >> Anyone see what I am missing? >> >> Gary >> >> >> Calculate your Loan >> >> >> >> >> >> Loan Amount >> USD >> > src="images/help.png" class="noborder"/> >> >> >> Type of >> Loan >> >> >> Installment >> Balloon >> >> > src="images/help.png" class="noborder"/> >> >> >> Term of Loan >> >> Months >> > onmouseout="UnTip()">> /> >> >> >> Interest >> Rate >> Per >> Annum> onmouseover="Tip('Percentage (%) charged on loan on an annual basis. >> Please see our FAQs for information on usury rates. If no >> amount is entered this will be 0%.')" onmouseout="UnTip()">> src="images/help.png" class="noborder" /> >> >> >> >> >> >> >> > >> function amortizationTable($paymentNum, $periodicPayment, $balance, >>$monthlyInterest) { >> $paymentInterest = round($balance * $monthlyInterest,2); >> $paymentPrincipal = round($periodicPayment - $paymentInterest,2); >> $newBalance = round($balance - $paymentPrincipal,2); >> print " >>$paymentNum >>\$".number_format($balance,2)." >>\$".number_format($periodicPayment,2)." >>\$".number_format($paymentInterest,2)." >>\$".number_format($paymentPrincipal,2)." >>"; >> # If balance not yet zero, recursively call amortizationTable() >> if ($newBalance > 0) { >> $paymentNum++; >> amortizationTable($paymentNum, $periodicPayment, $newBalance, >> $monthlyInterest); >> } else { >> exit; >> } >> } #end amortizationTable() >> >># Loan balance >>$balance =($_POST['loan_amount']); >> >># Loan interest rate >>$interestRate = ($_POST['int_rate']); >> >># Monthly interest rate >>$monthlyInterest = ("$interestRate / 12"); >> >># Term length of the loan, in years. >>$termLength =($_POST['loan_term']); >> >># Number of payments per year. >>$paymentsPerYear = 12; >> >># Payment iteration >>$paymentNumber =($_POST['loan_term']); >> >># Perform preliminary calculations >>$totalPayments = $termLength * $paymentsPerYear; >>$intCalc = 1 + $interestRate / $paymentsPerYear; >>$periodicPayment = $balance * pow($intCalc,$totalPayments) * >> ($intCalc - 1) / >> (pow($intCalc,$totalPayments) - 1); >>$periodicPayment = round($periodicPayment,2); >> >># Create table >>echo ""; >>print " >> Payment >> NumberBalance >> PaymentInterestPrincipal >> "; >> >># Call recursive function >>amortizationTable($paymentNumber, $periodicPayment, $balance, >> $monthlyInterest); >> >># Close table >>print ""; >> >> ?> >> >> >> >> __ Information from ESET Smart Security, version of virus >> signature database 4932 (20100310) __ >> >> The message was checked by ESET Smart Security. >> >> http://www.eset.com >> >> >> >> >> >> > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Execution order of PHP
On Wed, Mar 10, 2010 at 14:41, Bob McConnell wrote: > From: Auke van Slooten > >> In a hobby project I'm relying on the order in which the following > piece >> of PHP code is executed: >> >> $client->system->multiCall( >> $client->methodOne(), >> $client->methodTwo() >> ); >> >> Currently PHP always resolves $client->system (and executes the __get > on >> $client) before resolving the arguments to the multiCall() method > call. >> >> Is this order something that is specified by PHP and so can be relied >> upon to stay the same in the future or is it just how it currently > works. >> >> If it cannot be relied upon to stay this way, I will have to rewrite > the >> multiCall method and API... > > Think about it from the parser's point of view. It has to evaluate > $client->system to determine the parameter list for multiCall(). Then it > has to evaluate those parameters before it can stuff their values into > the stack so it can call the function. That's not true. It's entirely possible making languages that are lazy evaluated. Haskell is an example of that. -- Daniel Egeberg -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Division by 0
Looks to me like you are closing your form before you put anything in it. Therefore, the loan_amount is not set making the value 0. Follow the math, and you are dividing by 1-1. Change this line: to: and you should be good to go. Joseph Gary wrote: I have a mortgage amortization script that was working fine,now it seems to have gone awry. Below is the entire script plus input page. I am getting an error Warning: Division by zero in /home/content/J/a/y/Jayski/html/one2one/Ricksrecursivefunctions.php on line 47 Which is (pow($intCalc,$totalPayments) - 1); Frankly I am not even sure the information is being passed to the script. Anyone see what I am missing? Gary Calculate your Loan Loan Amount USD src="images/help.png" class="noborder"/> Type of Loan Installment Balloon class="noborder"/> Term of Loan Months src="images/help.png" class="noborder" /> Interest Rate Per Annum/> $paymentNum \$".number_format($balance,2)." \$".number_format($periodicPayment,2)." \$".number_format($paymentInterest,2)." \$".number_format($paymentPrincipal,2)." "; # If balance not yet zero, recursively call amortizationTable() if ($newBalance > 0) { $paymentNum++; amortizationTable($paymentNum, $periodicPayment, $newBalance, $monthlyInterest); } else { exit; } } #end amortizationTable() # Loan balance $balance =($_POST['loan_amount']); # Loan interest rate $interestRate = ($_POST['int_rate']); # Monthly interest rate $monthlyInterest = ("$interestRate / 12"); # Term length of the loan, in years. $termLength =($_POST['loan_term']); # Number of payments per year. $paymentsPerYear = 12; # Payment iteration $paymentNumber =($_POST['loan_term']); # Perform preliminary calculations $totalPayments = $termLength * $paymentsPerYear; $intCalc = 1 + $interestRate / $paymentsPerYear; $periodicPayment = $balance * pow($intCalc,$totalPayments) * ($intCalc - 1) / (pow($intCalc,$totalPayments) - 1); $periodicPayment = round($periodicPayment,2); # Create table echo ""; print " Payment NumberBalance PaymentInterestPrincipal "; # Call recursive function amortizationTable($paymentNumber, $periodicPayment, $balance, $monthlyInterest); # Close table print ""; ?> __ Information from ESET Smart Security, version of virus signature database 4932 (20100310) __ The message was checked by ESET Smart Security. http://www.eset.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Division by 0
I have a mortgage amortization script that was working fine,now it seems to have gone awry. Below is the entire script plus input page. I am getting an error Warning: Division by zero in /home/content/J/a/y/Jayski/html/one2one/Ricksrecursivefunctions.php on line 47 Which is (pow($intCalc,$totalPayments) - 1); Frankly I am not even sure the information is being passed to the script. Anyone see what I am missing? Gary Calculate your Loan Loan Amount USD Type of Loan Installment Balloon Term of Loan Months Interest Rate Per Annum $paymentNum \$".number_format($balance,2)." \$".number_format($periodicPayment,2)." \$".number_format($paymentInterest,2)." \$".number_format($paymentPrincipal,2)." "; # If balance not yet zero, recursively call amortizationTable() if ($newBalance > 0) { $paymentNum++; amortizationTable($paymentNum, $periodicPayment, $newBalance, $monthlyInterest); } else { exit; } } #end amortizationTable() # Loan balance $balance =($_POST['loan_amount']); # Loan interest rate $interestRate = ($_POST['int_rate']); # Monthly interest rate $monthlyInterest = ("$interestRate / 12"); # Term length of the loan, in years. $termLength =($_POST['loan_term']); # Number of payments per year. $paymentsPerYear = 12; # Payment iteration $paymentNumber =($_POST['loan_term']); # Perform preliminary calculations $totalPayments = $termLength * $paymentsPerYear; $intCalc = 1 + $interestRate / $paymentsPerYear; $periodicPayment = $balance * pow($intCalc,$totalPayments) * ($intCalc - 1) / (pow($intCalc,$totalPayments) - 1); $periodicPayment = round($periodicPayment,2); # Create table echo ""; print " Payment NumberBalance PaymentInterestPrincipal "; # Call recursive function amortizationTable($paymentNumber, $periodicPayment, $balance, $monthlyInterest); # Close table print ""; ?> __ Information from ESET Smart Security, version of virus signature database 4932 (20100310) __ The message was checked by ESET Smart Security. http://www.eset.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Array Search Problem
> > did you read the help for those functions on php.net? Yes, I found a "recursive" way to find out the "index" like I wanted, by doing something like $from = explode("-", $from); $state_colors= explode("-", $state_colors); $change = explode("-",$change); $count = count($new_array); $i=0; foreach ($new_array as $key => $value){ echo $i . " " . $key . " is " . $value . " miles away"; $i++; } You can see it is not very elegant, and plus, I created the $new_array so I could do the ordering according to the values of the change array. I can tell that since this is not a single array, which is probably why array_search does not work. Since I don't need the "value" of my "new_array" here, I am still finding out how to "strip off" the values here without having to flatten my array. Is what I am trying to do here possible? Or, is there a trick in array_search that I could use to find the index without having to strip off anything? Thanks for your help. Alice > > On Wed, Mar 10, 2010 at 4:12 PM, Alice Wei wrote: > > > > Hi, > > > > I have the code as shown in the following that I am trying to create the > > image of based on the file loaded into the file and additional edits. The > > problem here appears to be that no matter what value I have in the > > $distance_to_destination variable, it does not affect any changes on the > > map. What I am trying to do here is to create a map based on the pre-passed > > through colors of individual states from another program, but I have to > > match up the colors based on the values of the correct states. > > > > I figured that I may have problems with > > > >$key= array_search($location2,$from); //Find out the position of the > > index in the array > > > >$colors_style = ";fill:" . $state_colors[$key]; //Use the index from > > array_search to apply to the color index > > > > Obviously, it is not applying the colors to the states that I would like > > other than doing it one by one as the order of what is in the $from > > variable. Could someone please give me some hints on how I could do the > > array_search here based on the "value" of the values in the > > $distance_to_distance and apply the color to the states? > > > > > > > header("Content-type: image/svg+xml"); //Outputting an SVG > > > > $from = $_GET['from']; > > $state_colors= $_GET['state_colors']; > > $distance_to_destination= $_GET['distance_to_destination']; > > > > $from = explode("-", $from); > > $state_colors= explode("-", $state_colors); > > $change = explode("-",$change); > > > > #Load the Map > > $ourFileName= "USA_Counties_with_FIPS_and_names.svg"; > > $fh = fopen($ourFileName, "r") or die("Can't open file"); > > $contents = fread($fh,filesize($ourFileName)); > > $lines2= file($ourFileName); > > > > foreach ($lines2 as $line_num => $line2) { > > > > $style_line_num = $line_num+3; > > $line2 = trim($line2); > > > > if(preg_match("/^style/",$line2)) { > > > > $rest = substr($line2,0,-1); > > > > for ($j=$line_num;$j<=$style_line_num;$j++){ > > if(preg_match("/inkscape:label/",$lines2[$j])) { > >$location = explode("=",$lines2[$j]); > >$location2 = substr($location[1],1,-6); > > > >if(in_array($location2, $from)) { > > > > $key= array_search($location2,$from); //Find out the position > > of the index in the array > > $colors_style = ";fill:" . $state_colors[$key]; //Use the > > index from array_search to apply to the color index > > $rest2 = substr($line2,0,-1). $colors_style . "\""; > > echo $rest2 . "\n"; > >} > >else echo $line2 . "\n"; > > > > } //end preg_match inkscape > > } //end for loop > > } //If preg_match style > > > > else echo $line2 . "\n"; //else if preg_match style > > } //end for each > > > > fclose($fh); > > ?> > > > > Thanks for your help. > > > > Alice > > > > _ > > Hotmail: Trusted email with Microsoft’s powerful SPAM protection. > > http://clk.atdmt.com/GBL/go/201469226/direct/01/ _ Hotmail: Powerful Free email with security by Microsoft. http://clk.atdmt.com/GBL/go/201469230/direct/01/
Re: [PHP] Array Search Problem
did you read the help for those functions on php.net? On Wed, Mar 10, 2010 at 4:12 PM, Alice Wei wrote: > > Hi, > > I have the code as shown in the following that I am trying to create the > image of based on the file loaded into the file and additional edits. The > problem here appears to be that no matter what value I have in the > $distance_to_destination variable, it does not affect any changes on the map. > What I am trying to do here is to create a map based on the pre-passed > through colors of individual states from another program, but I have to match > up the colors based on the values of the correct states. > > I figured that I may have problems with > > $key= array_search($location2,$from); //Find out the position of the index > in the array > > $colors_style = ";fill:" . $state_colors[$key]; //Use the index from > array_search to apply to the color index > > Obviously, it is not applying the colors to the states that I would like > other than doing it one by one as the order of what is in the $from variable. > Could someone please give me some hints on how I could do the array_search > here based on the "value" of the values in the $distance_to_distance and > apply the color to the states? > > > header("Content-type: image/svg+xml"); //Outputting an SVG > > $from = $_GET['from']; > $state_colors= $_GET['state_colors']; > $distance_to_destination= $_GET['distance_to_destination']; > > $from = explode("-", $from); > $state_colors= explode("-", $state_colors); > $change = explode("-",$change); > > #Load the Map > $ourFileName= "USA_Counties_with_FIPS_and_names.svg"; > $fh = fopen($ourFileName, "r") or die("Can't open file"); > $contents = fread($fh,filesize($ourFileName)); > $lines2= file($ourFileName); > > foreach ($lines2 as $line_num => $line2) { > > $style_line_num = $line_num+3; > $line2 = trim($line2); > > if(preg_match("/^style/",$line2)) { > > $rest = substr($line2,0,-1); > > for ($j=$line_num;$j<=$style_line_num;$j++){ > if(preg_match("/inkscape:label/",$lines2[$j])) { > $location = explode("=",$lines2[$j]); > $location2 = substr($location[1],1,-6); > > if(in_array($location2, $from)) { > > $key= array_search($location2,$from); //Find out the position of > the index in the array > $colors_style = ";fill:" . $state_colors[$key]; //Use the index > from array_search to apply to the color index > $rest2 = substr($line2,0,-1). $colors_style . "\""; > echo $rest2 . "\n"; > } > else echo $line2 . "\n"; > > } //end preg_match inkscape > } //end for loop > } //If preg_match style > > else echo $line2 . "\n"; //else if preg_match style > } //end for each > > fclose($fh); > ?> > > Thanks for your help. > > Alice > > _ > Hotmail: Trusted email with Microsoft’s powerful SPAM protection. > http://clk.atdmt.com/GBL/go/201469226/direct/01/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] RE: Array Search Not Working?
> > I'm still a little foggy on what you're doing, but doing, but does this > help? > > $from = explode("-", $from); > $state_colors = explode("-", $state_colors); > $change = explode("-", $change); > > $old = array_combine($from, $state_colors); > $new = array_combine($from, $change); > > //show all values > foreach($old as $key => $val) { > echo "{$key} old={$old[$key]} new={$new[$key]}\n"; > } > > //lookup a particular value > $test = "Muskogee, OK"; > echo "TEST={$test} old={$old[$test]} new={$new[$test]}\n"; > Well, here is the weird part. put up the last 3 lines of your code here into mine, and here is the output:TEST=Muskogee, OK old= new= I am starting to wonder if there are other things hidden inside the "values" that seems like that the values of the new array (the state and counties part) are the same as the original when I tried to do the comparison. This is what I mean by the fact that my array_search does not work, and all I am trying to do is to find the index, so I can do stateColors[$index] later on and color my map. Have I done something wrong here that causes the code you provided not to spit out anything here? This is what I have: $from = explode("-", $from); $state_colors= explode("-", $state_colors); $change = explode("-",$change); $new_array = array_combine($from,$change); asort($new_array); foreach ($new_array as $key => $value) echo $key . " is " . $value . " miles away"; Thanks. Alice _ Hotmail: Trusted email with Microsoft’s powerful SPAM protection. http://clk.atdmt.com/GBL/go/201469226/direct/01/
[PHP] Re: Array Search Not Working?
Alice Wei wrote: > From: aj...@alumni.iu.edu > To: nos...@mckenzies.net > CC: php-general@lists.php.net > Subject: RE: Array Search Not Working? > Date: Wed, 10 Mar 2010 11:21:26 -0500 I'm still a little foggy on what you're doing, but doing, but does this help? $from = explode("-", $from); $state_colors = explode("-", $state_colors); $change = explode("-", $change); $old = array_combine($from, $state_colors); $new = array_combine($from, $change); //show all values foreach($old as $key => $val) { echo "{$key} old={$old[$key]} new={$new[$key]}\n"; } //lookup a particular value $test = "Muskogee, OK"; echo "TEST={$test} old={$old[$test]} new={$new[$test]}\n"; /* I'm proud to be an Okie from Muskogee, A place where even squares can have a ball We still wave Old Glory down at the courthouse, And white lightnin's still the biggest thrill of all */ -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] RE: Array Search Not Working?
From: aj...@alumni.iu.edu To: nos...@mckenzies.net CC: php-general@lists.php.net Subject: RE: Array Search Not Working? Date: Wed, 10 Mar 2010 11:21:26 -0500 > Date: Wed, 10 Mar 2010 10:09:54 -0600 > From: nos...@mckenzies.net > To: aj...@alumni.iu.edu > CC: php-general@lists.php.net > Subject: Re: Array Search Not Working? > > Alice Wei wrote: > > Hi, > > > > I have two arrays here that I have combined into a new array, as shown > > here: > > > > $from = explode("-", $from); > > $change = explode("-",$change); > > $new_array = array_combine($from,$change); > > > > I then tried reading it from a file and do string matches, trying to find > > out the "key" using the array_search of the individual array elements. I > > seem to have no such luck, even when I copied one of the elements after I > > do a print_r($new_array); > > > > Here is the code, > > > > foreach ($lines2 as $line_num => $line2) { > > $style_line_num = $line_num+3; > > > > if(preg_match("/^style/",$line2)) { > > > > if(preg_match("/inkscape:label/",$lines2[$style_line_num])) { > > $location = explode("=",$lines2[$style_line_num]); > > $location2 = substr($patient_location[1],1,-6); > > > > if(in_array($location2, $from)) { > > $key= array_search($location2,$new_array); //Find out the > > position of the index in the array > > echo "Key " . $key . ""; //This only gives me a blank > > space after the word Key > > > > } > > > > } //end preg_match inkscape > >} //If preg_match style > > > > I looked at the example from > > http://php.net/manual/en/function.array-search.php, and looks like what I > > am trying to do here is possible, and yet, why am I not getting a proper > > key return? > > > > Thanks for your help. > > > > Alice > > > > _ > > Hotmail: Powerful Free email with security by Microsoft. > > http://clk.atdmt.com/GBL/go/201469230/direct/01/ > > It's not clear what you are doing, but here is the problem that you are > asking about. array_combine() builds an array using the values from > $from as the keys of the new array and the values from change as the > values of the new array. > > So here, if $locations2 is a value in the $from array: > if(in_array($location2, $from)) { > > But here you are searching the values of $new_array which are copies of > the values from $to. > $key= array_search($location2,$new_array); > > > -- > Thanks! > -Shawn Hi, Looks like I have figured out how to get it to sort numerically after the print out , but still I cannot get it to do the array_search to find out the index of the "element" in this "new_array". Here is the code, $from = "Adair, OK-Alfalfa, OK-Atoka, OK-Beaver, OK-Beckham, OK-Blaine, OK-Bryan, OK-Caddo, OK-Canadian, OK-Carter, OK-Cherokee, OK-Choctaw, OK-Cimarron, OK-Cleveland, OK-Coal, OK-Comanche, OK-Cotton, OK-Craig, OK-Creek, OK-Custer, OK-Delaware, OK-Dewey, OK-Ellis, OK-Garfield, OK-Garvin, OK-Grady, OK-Grant, OK-Greer, OK-Harmon, OK-Harper, OK-Haskell, OK-Hughes, OK-Jackson, OK-Jefferson, OK-Johnston, OK-Kay, OK-Kingfisher, OK-Kiowa, OK-Latimer, OK-Le Flore, OK-Lincoln, OK-Logan, OK-Love, OK-Major, OK-Marshall, OK-Mayes, OK-McClain, OK-McCurtain, OK-McIntosh, OK-Murray, OK-Muskogee, OK-Noble, OK-Nowata, OK-Okfuskee, OK-Oklahoma, OK-Okmulgee, OK-Osage, OK-Ottawa, OK-Pawnee, OK-Payne, OK-Pittsburg, OK-Pontotoc, OK-Pottawatomie, OK-Pushmataha, OK-Roger Mills, OK-Rogers, OK-Seminole, OK-Sequoyah, OK-Stephens, OK-Texas, OK-Tillman, OK-Tulsa, OK-Wagoner, OK-Washington, OK-Washita, OK-Woods, OK-Woodward, OK "; $state_colors= "#CC-#CC-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF"; $change= "207-158-189-220-134-74.9-174-75.1-38-125-173-215-390-39-141-92.1-121-175-80.1-95.4-191-124-169-101-77-52-117-155-188-176-169-114-158-122-141-107-43-122-181-223-53.7-41.5-131-112-144-147-48-249-141-101-155-81.4-158-92.3-16.3-105-153-186-108-69.2-146-103-53.4-225-140-136-80.4-179-93.3-277-136-110-136-143-103-183-141";; $from = explode("-", $from); $state_colors= explode("-", $state_colors); $change = explode("-",$change); $new_array = array_combine($from,$change); asort($new_array); foreach ($new_array
[PHP] RE: Array Search Not Working?
> Date: Wed, 10 Mar 2010 10:09:54 -0600 > From: nos...@mckenzies.net > To: aj...@alumni.iu.edu > CC: php-general@lists.php.net > Subject: Re: Array Search Not Working? > > Alice Wei wrote: > > Hi, > > > > I have two arrays here that I have combined into a new array, as shown > > here: > > > > $from = explode("-", $from); > > $change = explode("-",$change); > > $new_array = array_combine($from,$change); > > > > I then tried reading it from a file and do string matches, trying to find > > out the "key" using the array_search of the individual array elements. I > > seem to have no such luck, even when I copied one of the elements after I > > do a print_r($new_array); > > > > Here is the code, > > > > foreach ($lines2 as $line_num => $line2) { > > $style_line_num = $line_num+3; > > > > if(preg_match("/^style/",$line2)) { > > > > if(preg_match("/inkscape:label/",$lines2[$style_line_num])) { > > $location = explode("=",$lines2[$style_line_num]); > > $location2 = substr($patient_location[1],1,-6); > > > > if(in_array($location2, $from)) { > > $key= array_search($location2,$new_array); //Find out the > > position of the index in the array > > echo "Key " . $key . ""; //This only gives me a blank > > space after the word Key > > > > } > > > > } //end preg_match inkscape > >} //If preg_match style > > > > I looked at the example from > > http://php.net/manual/en/function.array-search.php, and looks like what I > > am trying to do here is possible, and yet, why am I not getting a proper > > key return? > > > > Thanks for your help. > > > > Alice > > > > _ > > Hotmail: Powerful Free email with security by Microsoft. > > http://clk.atdmt.com/GBL/go/201469230/direct/01/ > > It's not clear what you are doing, but here is the problem that you are > asking about. array_combine() builds an array using the values from > $from as the keys of the new array and the values from change as the > values of the new array. > > So here, if $locations2 is a value in the $from array: > if(in_array($location2, $from)) { > > But here you are searching the values of $new_array which are copies of > the values from $to. > $key= array_search($location2,$new_array); > > > -- > Thanks! > -Shawn Here is what I wanted to do: $from = "Adair, OK-Alfalfa, OK-Atoka, OK-Beaver, OK-Beckham, OK-Blaine, OK-Bryan, OK-Caddo, OK-Canadian, OK-Carter, OK-Cherokee, OK-Choctaw, OK-Cimarron, OK-Cleveland, OK-Coal, OK-Comanche, OK-Cotton, OK-Craig, OK-Creek, OK-Custer, OK-Delaware, OK-Dewey, OK-Ellis, OK-Garfield, OK-Garvin, OK-Grady, OK-Grant, OK-Greer, OK-Harmon, OK-Harper, OK-Haskell, OK-Hughes, OK-Jackson, OK-Jefferson, OK-Johnston, OK-Kay, OK-Kingfisher, OK-Kiowa, OK-Latimer, OK-Le Flore, OK-Lincoln, OK-Logan, OK-Love, OK-Major, OK-Marshall, OK-Mayes, OK-McClain, OK-McCurtain, OK-McIntosh, OK-Murray, OK-Muskogee, OK-Noble, OK-Nowata, OK-Okfuskee, OK-Oklahoma, OK-Okmulgee, OK-Osage, OK-Ottawa, OK-Pawnee, OK-Payne, OK-Pittsburg, OK-Pontotoc, OK-Pottawatomie, OK-Pushmataha, OK-Roger Mills, OK-Rogers, OK-Seminole, OK-Sequoyah, OK-Stephens, OK-Texas, OK-Tillman, OK-Tulsa, OK-Wagoner, OK-Washington, OK-Washita, OK-Woods, OK-Woodward, OK "; $state_colors= "#CC-#CC-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#FF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF-#0DCCFF"; $change= "207-158-189-220-134-74.9-174-75.1-38-125-173-215-390-39-141-92.1-121-175-80.1-95.4-191-124-169-101-77-52-117-155-188-176-169-114-158-122-141-107-43-122-181-223-53.7-41.5-131-112-144-147-48-249-141-101-155-81.4-158-92.3-16.3-105-153-186-108-69.2-146-103-53.4-225-140-136-80.4-179-93.3-277-136-110-136-143-103-183-141";; $from = explode("-", $from); $state_colors= explode("-", $state_colors); $change = explode("-",$change); $new_array = array_combine($from,$change); print_r($new_array); Although array_combine does put the two arrays together, I cannot really "sort" with the array, because there is text and numeric in there. Plus, array_search seems to be only able to search through one dimension. I would really like to know how I can first sort through the $new_array according to the "numeric" and NOT the "text". I then would like to use the "index" aft
Re: [PHP] Execution order of PHP
Andrew Ballard wrote: I'm not sure you would want to assign null to $client->system. After all, __set() might not be defined. I agree with Rob here. If order is really crucial, then call the statements in the correct order: system; /** * You should add some handling here to make sure that * $system is really an object that implements your * multiCall() method, and not something else (like null). */ $system->multiCall( $client->methodOne(), $client->methodTwo() ); ?> I agree with both of you. If you want it ironclad and you cannot change the API, then this is how I would do it. The point is that I _can_ change the API, but I like how simple it looks. The backup plan is to do something like: $client->system->multiCall( $client->__defer()->methodOne(), $client->__defer()->methodTwo() ); The only problem with this is that I'm polluting the $client 'namespace' with a __defer method. And it looks less clean... :) Now if the consensus is that you absolutely cannot rely on the execution order in this case (not for the order in which function parameters are evaluated, I don't care about that) then I will just change my API and remember with fondness what I could not have... regards, Auke van Slooten Muze -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Array Search Not Working?
Alice Wei wrote: > Hi, > > I have two arrays here that I have combined into a new array, as shown here: > > $from = explode("-", $from); > $change = explode("-",$change); > $new_array = array_combine($from,$change); > > I then tried reading it from a file and do string matches, trying to find out > the "key" using the array_search of the individual array elements. I seem to > have no such luck, even when I copied one of the elements after I do a > print_r($new_array); > > Here is the code, > > foreach ($lines2 as $line_num => $line2) { > $style_line_num = $line_num+3; > > if(preg_match("/^style/",$line2)) { > > if(preg_match("/inkscape:label/",$lines2[$style_line_num])) { > $location = explode("=",$lines2[$style_line_num]); > $location2 = substr($patient_location[1],1,-6); > > if(in_array($location2, $from)) { > $key= array_search($location2,$new_array); //Find out the > position of the index in the array > echo "Key " . $key . ""; //This only gives me a blank space > after the word Key > > } > > } //end preg_match inkscape >} //If preg_match style > > I looked at the example from > http://php.net/manual/en/function.array-search.php, and looks like what I am > trying to do here is possible, and yet, why am I not getting a proper key > return? > > Thanks for your help. > > Alice > > _ > Hotmail: Powerful Free email with security by Microsoft. > http://clk.atdmt.com/GBL/go/201469230/direct/01/ It's not clear what you are doing, but here is the problem that you are asking about. array_combine() builds an array using the values from $from as the keys of the new array and the values from change as the values of the new array. So here, if $locations2 is a value in the $from array: if(in_array($location2, $from)) { But here you are searching the values of $new_array which are copies of the values from $to. $key= array_search($location2,$new_array); -- 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] Execution order of PHP
2010/3/10 Andrew Ballard : > On Wed, Mar 10, 2010 at 9:54 AM, Bruno Fajardo wrote: > [snip] >> 2010/3/10 Auke van Slooten : >>> This is not what I meant. I should perhaps mention that it's an xml-rpc >>> client and the method calls are remote method calls. The multiCall method >>> gathers multiple method calls into a single request. >>> >>> The trick I'm using now is to set a private property in the $client->__get() >>> method when the property you're accessing is 'system'. From then untill you >>> call the method 'multiCall', instead of calling the methods (in this case >>> methodOne and methodTwo) the client creates a new object with the call >>> information (method name and arguments) and returns that. In multiCall all >>> arguments are therefor call information objects and multicall creates a >>> single request based on that information. >> >> Hmm, you cleared that to me now... If you need to first create the >> property "system" and then call a method in that object "system", >> can't you do something like: >> >> $client->system = null; >> $client->system->multiCall( >> $client->methodOne(), >> $client->methodTwo() >> ); >> >> I'm not testing these snippets of code, so sorry if I'm getting something >> wrong. >> >> Cheers, >> Bruno. >> > [snip] > > I'm not sure you would want to assign null to $client->system. After > all, __set() might not be defined. Yes, you're right, Andrew. Setting the property to null is not the best choice in this case. > > I agree with Rob here. If order is really crucial, then call the > statements in the correct order: > > > /** > * causes $client to call __get() in order to resolve > * 'system' > */ > $system = $client->system; > This was my point too, to create the object before the call to multiCall(), I just messed my example with the null assignment... :-) The code you suggested must solve the OP issue. Cheers, Bruno. > > /** > * You should add some handling here to make sure that > * $system is really an object that implements your > * multiCall() method, and not something else (like null). > */ > > > $system->multiCall( > $client->methodOne(), > $client->methodTwo() > ); > > ?> > > > > Andrew > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Execution order of PHP
On Wed, Mar 10, 2010 at 9:54 AM, Bruno Fajardo wrote: [snip] > 2010/3/10 Auke van Slooten : >> This is not what I meant. I should perhaps mention that it's an xml-rpc >> client and the method calls are remote method calls. The multiCall method >> gathers multiple method calls into a single request. >> >> The trick I'm using now is to set a private property in the $client->__get() >> method when the property you're accessing is 'system'. From then untill you >> call the method 'multiCall', instead of calling the methods (in this case >> methodOne and methodTwo) the client creates a new object with the call >> information (method name and arguments) and returns that. In multiCall all >> arguments are therefor call information objects and multicall creates a >> single request based on that information. > > Hmm, you cleared that to me now... If you need to first create the > property "system" and then call a method in that object "system", > can't you do something like: > > $client->system = null; > $client->system->multiCall( > $client->methodOne(), > $client->methodTwo() > ); > > I'm not testing these snippets of code, so sorry if I'm getting something > wrong. > > Cheers, > Bruno. > [snip] I'm not sure you would want to assign null to $client->system. After all, __set() might not be defined. I agree with Rob here. If order is really crucial, then call the statements in the correct order: system; /** * You should add some handling here to make sure that * $system is really an object that implements your * multiCall() method, and not something else (like null). */ $system->multiCall( $client->methodOne(), $client->methodTwo() ); ?> Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Execution order of PHP
2010/3/10 Auke van Slooten : > Bruno Fajardo wrote: >> >> 2010/3/10 Auke van Slooten >>> >>> Hi, >>> >>> In a hobby project I'm relying on the order in which the following piece >>> of PHP code is executed: >>> >>> $client->system->multiCall( >>> $client->methodOne(), >>> $client->methodTwo() >>> ); >> >> Can't you call the methods $client->methodOne() and >> $client->methodTwo() before the call to $client->system->multiCall()? >> That way, you could store they values in local variables, and then >> pass them to the $client->system->multiCall(), assuring that those >> methods are executed before the multiCall(). Something like: >> >> $methodOne = $client->methodOne(); >> $methodTwo = $client->methodTwo(); >> $client->system->multiCall($methodOne, $methodTwo); > > Hi, > > This is not what I meant. I should perhaps mention that it's an xml-rpc > client and the method calls are remote method calls. The multiCall method > gathers multiple method calls into a single request. > > The trick I'm using now is to set a private property in the $client->__get() > method when the property you're accessing is 'system'. From then untill you > call the method 'multiCall', instead of calling the methods (in this case > methodOne and methodTwo) the client creates a new object with the call > information (method name and arguments) and returns that. In multiCall all > arguments are therefor call information objects and multicall creates a > single request based on that information. Hmm, you cleared that to me now... If you need to first create the property "system" and then call a method in that object "system", can't you do something like: $client->system = null; $client->system->multiCall( $client->methodOne(), $client->methodTwo() ); I'm not testing these snippets of code, so sorry if I'm getting something wrong. Cheers, Bruno. > > So in your example the client would simply call methodOne and methodTwo and > return the results. Then it would try to do a multiCall with whatever the > previous methods have returned. > > regards, > Auke van Slooten > Muze > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Execution order of PHP
Auke van Slooten wrote: Bob McConnell wrote: From: Auke van Slooten In a hobby project I'm relying on the order in which the following piece of PHP code is executed: $client->system->multiCall( $client->methodOne(), $client->methodTwo() ); Think about it from the parser's point of view. It has to evaluate $client->system to determine the parameter list for multiCall(). Then it has to evaluate those parameters before it can stuff their values into the stack so it can call the function. But, whether it evaluates the parameter list left-to-right or vice versa is implementation dependent. I don't believe you can rely on it always being the same unless you always use the same interpreter. I don't mind about the order in which the parameters are evaluated. The only thing that must stay the same for my code to work as designed is that $client->system is evaluated before any of the arguments to the multiCall method. Your explanation seems reasonable to me, but I've been informed by people that know more about parsers and compilers than me, that theoretically there is no requirement for this to be true... After a further education just now, it is possible for a compiler to parse the entire multiCall right to left, so it will first evaluate $client->methodTwo(), then $client->methodOne() and only then resolves $client->system->multiCall. Before evaluating this call, the compiler can still check whether the number of arguments matches the parameter list of the function definition. Anyway, the point is that I'd like to be able to write multiCall statements like written above instead of doing something like this: $client->system->multiCall( array( 'method' => 'methodOne', 'params' => array() ), array( 'method' => 'methodTwo', 'params' => array() ) ); regards, Auke van Slooten Muze I don't understand the point in a 10 message thread to ascertain the safety of what you are doing when you already know it is questionable in practice and that simply breaking the statements into multiple statements with temporary variables will provide a perfectly good solution. The work involved in breaking the code into multiple lines would be a fraction of that contributed to writing to the list. So the question now is... are you just looking to discuss the merits and demerits of implementation dependent processing order or do you want someone to tell you it's ok to write questionable code? Regardless of the point and what you end up doing, I would add a comment in your code explaining that the order of function evaluation is important. Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Array Search Not Working?
Hi, I have two arrays here that I have combined into a new array, as shown here: $from = explode("-", $from); $change = explode("-",$change); $new_array = array_combine($from,$change); I then tried reading it from a file and do string matches, trying to find out the "key" using the array_search of the individual array elements. I seem to have no such luck, even when I copied one of the elements after I do a print_r($new_array); Here is the code, foreach ($lines2 as $line_num => $line2) { $style_line_num = $line_num+3; if(preg_match("/^style/",$line2)) { if(preg_match("/inkscape:label/",$lines2[$style_line_num])) { $location = explode("=",$lines2[$style_line_num]); $location2 = substr($patient_location[1],1,-6); if(in_array($location2, $from)) { $key= array_search($location2,$new_array); //Find out the position of the index in the array echo "Key " . $key . ""; //This only gives me a blank space after the word Key } } //end preg_match inkscape } //If preg_match style I looked at the example from http://php.net/manual/en/function.array-search.php, and looks like what I am trying to do here is possible, and yet, why am I not getting a proper key return? Thanks for your help. Alice _ Hotmail: Powerful Free email with security by Microsoft. http://clk.atdmt.com/GBL/go/201469230/direct/01/
RE: [PHP] Execution order of PHP
From: Sándor Tamás > 2010.03.10. 14:41 keltezéssel, Bob McConnell írta: >> From: Auke van Slooten >> >>> In a hobby project I'm relying on the order in which the following >>> >> piece >> >>> of PHP code is executed: >>> >>> $client->system->multiCall( >>> $client->methodOne(), >>> $client->methodTwo() >>> ); >>> >>> Currently PHP always resolves $client->system (and executes the __get >>> >> on >> >>> $client) before resolving the arguments to the multiCall() method >>> >> call. >> >>> Is this order something that is specified by PHP and so can be relied >>> upon to stay the same in the future or is it just how it currently >>> >> works. >> >>> If it cannot be relied upon to stay this way, I will have to rewrite >>> >> the >> >>> multiCall method and API... >>> >> Think about it from the parser's point of view. It has to evaluate >> $client->system to determine the parameter list for multiCall(). Then it >> has to evaluate those parameters before it can stuff their values into >> the stack so it can call the function. But, whether it evaluates the >> parameter list left-to-right or vice versa is implementation dependent. >> I don't believe you can rely on it always being the same unless you >> always use the same interpreter. > > I think it cannot be that the evaluation order of the parameters is > implementation dependent. > Just think about it: >$someobject->method($a++, $a++); > > What will be the result? Or there has to be some directive to tell the > parser to evaluate the parameters from left to right or vice versa. > And if there isn't, in some future release, there has to be. The result of that line would be undefined in any language I am familiar with. I could manually implement a variation in assembler that would be safe, but nowhere else. You have too many operations in a row on a single variable without adequate checkpoints between them. Bob McConnell -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Execution order of PHP
Bob McConnell wrote: From: Auke van Slooten In a hobby project I'm relying on the order in which the following piece of PHP code is executed: $client->system->multiCall( $client->methodOne(), $client->methodTwo() ); Think about it from the parser's point of view. It has to evaluate $client->system to determine the parameter list for multiCall(). Then it has to evaluate those parameters before it can stuff their values into the stack so it can call the function. But, whether it evaluates the parameter list left-to-right or vice versa is implementation dependent. I don't believe you can rely on it always being the same unless you always use the same interpreter. I don't mind about the order in which the parameters are evaluated. The only thing that must stay the same for my code to work as designed is that $client->system is evaluated before any of the arguments to the multiCall method. Your explanation seems reasonable to me, but I've been informed by people that know more about parsers and compilers than me, that theoretically there is no requirement for this to be true... After a further education just now, it is possible for a compiler to parse the entire multiCall right to left, so it will first evaluate $client->methodTwo(), then $client->methodOne() and only then resolves $client->system->multiCall. Before evaluating this call, the compiler can still check whether the number of arguments matches the parameter list of the function definition. Anyway, the point is that I'd like to be able to write multiCall statements like written above instead of doing something like this: $client->system->multiCall( array( 'method' => 'methodOne', 'params' => array() ), array( 'method' => 'methodTwo', 'params' => array() ) ); regards, Auke van Slooten Muze -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Execution order of PHP
On Wed, 2010-03-10 at 15:20 +0100, Sándor Tamás wrote: > > 2010.03.10. 14:41 keltezéssel, Bob McConnell írta: > > From: Auke van Slooten > > > > > >> In a hobby project I'm relying on the order in which the following > >> > > piece > > > >> of PHP code is executed: > >> > >> $client->system->multiCall( > >> $client->methodOne(), > >> $client->methodTwo() > >> ); > >> > >> Currently PHP always resolves $client->system (and executes the __get > >> > > on > > > >> $client) before resolving the arguments to the multiCall() method > >> > > call. > > > >> Is this order something that is specified by PHP and so can be relied > >> upon to stay the same in the future or is it just how it currently > >> > > works. > > > >> If it cannot be relied upon to stay this way, I will have to rewrite > >> > > the > > > >> multiCall method and API... > >> > > Think about it from the parser's point of view. It has to evaluate > > $client->system to determine the parameter list for multiCall(). Then it > > has to evaluate those parameters before it can stuff their values into > > the stack so it can call the function. But, whether it evaluates the > > parameter list left-to-right or vice versa is implementation dependent. > > I don't believe you can rely on it always being the same unless you > > always use the same interpreter. > > > > Bob McConnell > > > > > I think it cannot be that the evaluation order of the parameters is > implementation dependent. > Just think about it: >$someobject->method($a++, $a++); > > What will be the result? Or there has to be some directive to tell the > parser to evaluate the parameters from left to right or vice versa. > And if there isn't, in some future release, there has to be. > > SanTa > The order is implementation dependent, and just follows from other languages which behave exactly the same (I believe Java and C++ both do) This is the sort of example that's used as a reason to not rely on such behaviour. You just have to work around it I guess. Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] Execution order of PHP
2010.03.10. 14:41 keltezéssel, Bob McConnell írta: From: Auke van Slooten In a hobby project I'm relying on the order in which the following piece of PHP code is executed: $client->system->multiCall( $client->methodOne(), $client->methodTwo() ); Currently PHP always resolves $client->system (and executes the __get on $client) before resolving the arguments to the multiCall() method call. Is this order something that is specified by PHP and so can be relied upon to stay the same in the future or is it just how it currently works. If it cannot be relied upon to stay this way, I will have to rewrite the multiCall method and API... Think about it from the parser's point of view. It has to evaluate $client->system to determine the parameter list for multiCall(). Then it has to evaluate those parameters before it can stuff their values into the stack so it can call the function. But, whether it evaluates the parameter list left-to-right or vice versa is implementation dependent. I don't believe you can rely on it always being the same unless you always use the same interpreter. Bob McConnell I think it cannot be that the evaluation order of the parameters is implementation dependent. Just think about it: $someobject->method($a++, $a++); What will be the result? Or there has to be some directive to tell the parser to evaluate the parameters from left to right or vice versa. And if there isn't, in some future release, there has to be. SanTa smime.p7s Description: S/MIME Cryptographic Signature
Re: [PHP] Execution order of PHP
Bruno Fajardo wrote: 2010/3/10 Auke van Slooten Hi, In a hobby project I'm relying on the order in which the following piece of PHP code is executed: $client->system->multiCall( $client->methodOne(), $client->methodTwo() ); Can't you call the methods $client->methodOne() and $client->methodTwo() before the call to $client->system->multiCall()? That way, you could store they values in local variables, and then pass them to the $client->system->multiCall(), assuring that those methods are executed before the multiCall(). Something like: $methodOne = $client->methodOne(); $methodTwo = $client->methodTwo(); $client->system->multiCall($methodOne, $methodTwo); Hi, This is not what I meant. I should perhaps mention that it's an xml-rpc client and the method calls are remote method calls. The multiCall method gathers multiple method calls into a single request. The trick I'm using now is to set a private property in the $client->__get() method when the property you're accessing is 'system'. From then untill you call the method 'multiCall', instead of calling the methods (in this case methodOne and methodTwo) the client creates a new object with the call information (method name and arguments) and returns that. In multiCall all arguments are therefor call information objects and multicall creates a single request based on that information. So in your example the client would simply call methodOne and methodTwo and return the results. Then it would try to do a multiCall with whatever the previous methods have returned. regards, Auke van Slooten Muze -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Array Search Problem
Hi, I have the code as shown in the following that I am trying to create the image of based on the file loaded into the file and additional edits. The problem here appears to be that no matter what value I have in the $distance_to_destination variable, it does not affect any changes on the map. What I am trying to do here is to create a map based on the pre-passed through colors of individual states from another program, but I have to match up the colors based on the values of the correct states. I figured that I may have problems with $key= array_search($location2,$from); //Find out the position of the index in the array $colors_style = ";fill:" . $state_colors[$key]; //Use the index from array_search to apply to the color index Obviously, it is not applying the colors to the states that I would like other than doing it one by one as the order of what is in the $from variable. Could someone please give me some hints on how I could do the array_search here based on the "value" of the values in the $distance_to_distance and apply the color to the states? $line2) { $style_line_num = $line_num+3; $line2 = trim($line2); if(preg_match("/^style/",$line2)) { $rest = substr($line2,0,-1); for ($j=$line_num;$j<=$style_line_num;$j++){ if(preg_match("/inkscape:label/",$lines2[$j])) { $location = explode("=",$lines2[$j]); $location2 = substr($location[1],1,-6); if(in_array($location2, $from)) { $key= array_search($location2,$from); //Find out the position of the index in the array $colors_style = ";fill:" . $state_colors[$key]; //Use the index from array_search to apply to the color index $rest2 = substr($line2,0,-1). $colors_style . "\""; echo $rest2 . "\n"; } else echo $line2 . "\n"; } //end preg_match inkscape } //end for loop } //If preg_match style else echo $line2 . "\n"; //else if preg_match style } //end for each fclose($fh); ?> Thanks for your help. Alice _ Hotmail: Trusted email with Microsoft’s powerful SPAM protection. http://clk.atdmt.com/GBL/go/201469226/direct/01/
RE: [PHP] Execution order of PHP
From: Auke van Slooten > In a hobby project I'm relying on the order in which the following piece > of PHP code is executed: > > $client->system->multiCall( >$client->methodOne(), >$client->methodTwo() > ); > > Currently PHP always resolves $client->system (and executes the __get on > $client) before resolving the arguments to the multiCall() method call. > > Is this order something that is specified by PHP and so can be relied > upon to stay the same in the future or is it just how it currently works. > > If it cannot be relied upon to stay this way, I will have to rewrite the > multiCall method and API... Think about it from the parser's point of view. It has to evaluate $client->system to determine the parameter list for multiCall(). Then it has to evaluate those parameters before it can stuff their values into the stack so it can call the function. But, whether it evaluates the parameter list left-to-right or vice versa is implementation dependent. I don't believe you can rely on it always being the same unless you always use the same interpreter. Bob McConnell -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Execution order of PHP
2010/3/10 Auke van Slooten > > Hi, > > In a hobby project I'm relying on the order in which the following piece of > PHP code is executed: > > $client->system->multiCall( > $client->methodOne(), > $client->methodTwo() > ); > > Currently PHP always resolves $client->system (and executes the __get on > $client) before resolving the arguments to the multiCall() method call. Hi! Can't you call the methods $client->methodOne() and $client->methodTwo() before the call to $client->system->multiCall()? That way, you could store they values in local variables, and then pass them to the $client->system->multiCall(), assuring that those methods are executed before the multiCall(). Something like: $methodOne = $client->methodOne(); $methodTwo = $client->methodTwo(); $client->system->multiCall($methodOne, $methodTwo); Cheers, Bruno. > > Is this order something that is specified by PHP and so can be relied upon to > stay the same in the future or is it just how it currently works. > > If it cannot be relied upon to stay this way, I will have to rewrite the > multiCall method and API... > > regards, > Auke van Slooten > Muze > > -- > 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
[PHP] Execution order of PHP
Hi, In a hobby project I'm relying on the order in which the following piece of PHP code is executed: $client->system->multiCall( $client->methodOne(), $client->methodTwo() ); Currently PHP always resolves $client->system (and executes the __get on $client) before resolving the arguments to the multiCall() method call. Is this order something that is specified by PHP and so can be relied upon to stay the same in the future or is it just how it currently works. If it cannot be relied upon to stay this way, I will have to rewrite the multiCall method and API... regards, Auke van Slooten Muze -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Mail Function In PHP
Having worked at a decent sized, respectable ISP with 100,000+ customers sending email via Iron Ports (email scanners), even they would get put on a blacklist on a monthly basis. Hell it wouldn't surprise me if Gmail's SMTP servers got put on a black list at some point. There's seemingly hundreds of blacklists and whilst some play nice, others are very paranoid. Usually the good email servers will detect your on a blacklist then rate limit the number of emails it'll accept from you. If you keep pissing it off, by sending emails to non-existant addresses (something they REALLY hate), sending emails that are too big, or simply sending too many emails or emails with too many recipients, then it'll tighten the restrictions. Over time if your good then those restrictions will be released and eventually you'll be able to send at normal rates. -- Michael Kubler I believe in a better world. I support the Zeitgeist Movement -- www.zeitgeistaustralia.org Teus Benschop wrote: Once a domain or ip address was black listed, it was quite a process to get it unlisted again, and even then as soon as mail came from that domain, it got blacklisted again. Supposedly there is some certification process that official smtp relays need to go through so as to prove or certify that they won't allow spam to be sent through them, and take steps to remove offenders from using their relay. However, this is all guessing, and in the end we just gave up and used our ISP's official relay. Teus. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Anyone good with multiple SSL on Apache?
Thanks Per, well here is a short translation of this article: http://www.tech-nerds.de/blog/2009/02/apache2-mit-mehreren-ssl-virtualhosts/ If you havn't installed apache2-threaded-dev: You need the current verion of gnutls (download from gnu.org) Download, unpack, compile and install as usual. Than call ldconfig. And than install apache2-threaded-dev: ./configure --with.apxs2=/usr/bin/apxs2 make install (Which copies apache module (hopefully) to this path: /usr/lib/apache2/modules) Than create /etc/apache2/mods-enabled/gnutls.load with following entry: LoadModule gnutls_module /usr/lib/apache2/modules/mod_gnutls.so And you have to Create /etc/apache2/mods-enabled/gnutls.conf containing the following: GnuTLSCache dbm /var/cache/mod_gnutls_cache GnuTLSCacheTimeout 300 Well and than every vhost that has to use SSL needs an entry like this: ServerName www.example.de GnuTLSEnable on GnuTLSPriorities NORMAL GnuTLSCertificateFile /etc/certs/example_server.pem GnuTLSKeyFile /etc/certs/example_key.pem DocumentRoot "/var/www/example.de" ... regards Jochen Schultz P.S. I think i will have to give it a try right now. Per Jessen schrieb: Jochen Schultz wrote: AFAIK Apache 2 doesn't support virtual hosts for SSL. I think it does now - there was even a c't article on the topic not long ago. I'll see if I can find it. /Per -- Sport Import GmbH - Amtsgericht Oldenburg - Tel: +49-4405-9280-63 Industriestrasse 39 - HRB 1202900- 26188 Edewecht - GF: Michael Müllmann -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Anyone good with multiple SSL on Apache?
Per Jessen wrote: > Daniel Egeberg wrote: > >> On Mon, Mar 8, 2010 at 23:21, Skip Evans >> wrote: >>> D'oh! >>> >>> ...and I suppose there is just no way around that, eh? >>> >>> Skip >> >> You can use SNI, but it's not supported by all web servers and >> browsers. >> >> http://en.wikipedia.org/wiki/Server_Name_Indication >> > > I don't know about the browser support, but the Apache and SNI > implementation is well described in this article: > > http://www.heise.de/kiosk/archiv/ct/2009/23/174_kiosk (download for a > fee) > This looks like a pretty decent article too: http://en.gentoo-wiki.com/wiki/Apache2/SSL_and_Name_Based_Virtual_Hosts According to that, the following browsers support SNI: * Opera 8.0+ * Firefox 2+ * Internet Explorer 7+ (but not on Windows XP) * Safari 3.2.1+ -- Per Jessen, Zürich (-3.9°C) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Anyone good with multiple SSL on Apache?
Per Jessen wrote: > Jochen Schultz wrote: > >> AFAIK Apache 2 doesn't support virtual hosts for SSL. >> > > I think it does now - there was even a c't article on the topic not > long ago. I'll see if I can find it. http://www.heise.de/kiosk/archiv/ct/2009/23/174_kiosk (download for a fee) -- Per Jessen, Zürich (-3.9°C) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Anyone good with multiple SSL on Apache?
Daniel Egeberg wrote: > On Mon, Mar 8, 2010 at 23:21, Skip Evans > wrote: >> D'oh! >> >> ...and I suppose there is just no way around that, eh? >> >> Skip > > You can use SNI, but it's not supported by all web servers and > browsers. > > http://en.wikipedia.org/wiki/Server_Name_Indication > I don't know about the browser support, but the Apache and SNI implementation is well described in this article: http://www.heise.de/kiosk/archiv/ct/2009/23/174_kiosk (download for a fee) /Per -- Per Jessen, Zürich (-4.0°C) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Anyone good with multiple SSL on Apache?
Jochen Schultz wrote: > AFAIK Apache 2 doesn't support virtual hosts for SSL. > I think it does now - there was even a c't article on the topic not long ago. I'll see if I can find it. /Per -- Per Jessen, Zürich (-4.0°C) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php