Re: [PHP] professional code quick tip
On Tue, 2005-09-20 at 19:47, Thorsten Suckow-Homberg wrote: You could use the following statement: ?php switch (true) { case (0 $n = 4): $f = 1; break; case (5 $n = 7): $f = 2; break; case (8 $n = 12): $f = 3; break; default: $f = 4; break; } I'm certain that is illegal. Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] help out a noob w/ include switch?
[...] Try the following: 1) include() will only trigger a warning if the requested file is not within the include path. Thus, to make sure the file is found, you should use require() which triggers a fatal error and prevends the script from being executed if the given filename as the parameter cannot be found. This will give you probably a hint if there's something wrong with the include-path 2) Another suggestion would be to prepend ./ to the file you try to include: instead of include(file.php); you should use include(./file.php); ./ indicates that php should lookup the requested file in the directory the php-file resists in which called the include()-function. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] professional code quick tip
I'm certain that is illegal. Wanna bet? :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] professional code quick tip
Robert Cummings wrote: On Tue, 2005-09-20 at 19:47, Thorsten Suckow-Homberg wrote: You could use the following statement: ?php switch (true) { case (0 $n = 4): $f = 1; break; case (5 $n = 7): $f = 2; break; case (8 $n = 12): $f = 3; break; default: $f = 4; break; } I'm certain that is illegal. I don't think so, although I'm not able to test it right at this second. PHP compares the value within the switch statement to the value at each case. Only the case which is true will match true inside the switch statement, so it should actually work as intended. -- Jasper Bryant-Greene Freelance web developer http://jasper.bryant-greene.name/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] professional code quick tip
On Tue, 2005-09-20 at 19:55, Thorsten Suckow-Homberg wrote: I'm certain that is illegal. Wanna bet? :) $100... cuz I'm sure you didn't mean to compound those conditionals such that PHP doesn't understand them ;) snaffu:~ php foo.php Content-type: text/html X-Powered-By: PHP/4.4.0 br / bParse error/b: parse error, unexpected T_IS_SMALLER_OR_EQUAL in b/home/suds/foo.php/b on line b4/bbr / -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] professional code quick tip
Robert Cummings wrote: On Tue, 2005-09-20 at 19:55, Thorsten Suckow-Homberg wrote: I'm certain that is illegal. Wanna bet? :) $100... cuz I'm sure you didn't mean to compound those conditionals such that PHP doesn't understand them ;) Fair enough, but I believe it was the use of the switch statement for that purpose that he was pointing out; with a few modifications it works fine: ?php switch( true ) { case ( 0 $n $n = 4 ): $f = 1; break; case ( 5 $n $n = 7 ): $f = 2; break; case ( 8 $n $n = 12 ): $f = 3; break; default: $f = 4; break; } ? -- Jasper Bryant-Greene Freelance web developer http://jasper.bryant-greene.name/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] professional code quick tip
$100... cuz I'm sure you didn't mean to compound those conditionals such that PHP doesn't understand them ;) nargh... yes you're right... send me your account information along with your paypal login. I'll send you the money asap ;) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] SUCCESS! Re: help out a noob w/ include switch?
Thank you all for the kind help. I have The site working now (once i move it from the test loc. I'll post a link here. It's for a performance art festival here in vancouver). The was actually with $_GET in the switch as suggested by Ben. Thnks! I do however know about it's usage and even investigated it on php.net and google searches but for whatever reasons (novice??) I passed over it. One last time - Thank you! jt. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] professional code quick tip ---last---
thx to all -- final release good nigh! $f=0; if ( $ar[0]0 and $ar[0]=12) $f=1; elseif ( $ar[0]12 and $ar[0]=14) $f=2; elseif ( $ar[0]14 and $ar[0]=18) $f=3; if ( $ar[0]18) $f=4; 2005/9/21, Robert Cummings [EMAIL PROTECTED]: On Tue, 2005-09-20 at 19:20, adriano ghezzi wrote: hy guys this night I'm quite tired I need a little tip ok var n could be from 0 to 12 var f must be set f=1 if0n=4 f=2 if 5n=7 f=3 if 8n=12 f=4 if n12 due to my fatigue I coded four if-if else statement, in other languages it is possible use conditional epression in switch case like switch $n case (0n=4): but no in php any suggestion for more professional coding then 4 if/else statement For such a small set I'd say that's as good as it gets. However if there were 100 intervals you could try the following: function f( $n ) { $map = array ( // min, max,f array( 0, 4,1 ), array( 5, 7,2 ), array( 8,12,3 ), array( 17, null,4 ), ); foreach( $map as $criteria ) { if( $criteria[0] === null || $n $criteria[0] $criteria[1] === null || $n = $criteria[1] ) { return $criteria[2]; } } return null; } I think your code is flawed by the way, the lower endpoints are only compared for greater than value and not equal to value meaning $n with value 4 would not match any f value. Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: SUCCESS! Re: help out a noob w/ include switch?
jay thompson said the following on 09/20/05 17:35: Thank you all for the kind help. I have The site working now (once i move it from the test loc. I'll post a link here. It's for a performance art festival here in vancouver). The was actually with $_GET in the switch as suggested by Ben. Thnks! I do however know about it's usage and even investigated it on php.net and google searches but for whatever reasons (novice??) I passed over it. One last time - Thank you! You're very welcome, I'm glad it helped. At the noob point you'd be wise to get into the habit of referencing your user provided variables with $_GET, $_POST, and $_COOKIE regardless of whether register globals is on or off on your server as it's a good habit to get into and will save you grief in the future. More info here: http://ca3.php.net/variables.predefined BTW, what festival is the site for (I'm also in Vancouver)? - Ben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Wikimedia - php4
Hi I have just installed wikimedia on freebsd 5.3 with php4-4.4.0. After starting the program after a successful installation I get the error messages shown below. There are three eror from two lines of code. I have included the relevant code. Having just started to learn php, I am not competent to know how to set about solving this. Does anyone here have any idea what may be wrong or do you happen to know of a suitable forum or mailing list that could be helpful Thanks in advance david -- Errors from php4.log *** FIRST Error - reppeated twice: *** Notice: Only variable references should be returned by reference in /usr2/virtualwebs/forumkatrina.org/wiki/includes/ObjectCache.php on line 369 Notice: Only variable references should be returned by reference in /usr2/virtualwebs/forumkatrina.org/wiki/includes/ObjectCache.php on line 369 Line 369 indicated by ^^^ - function _unserialize( $serial ) { if( function_exists( 'gzinflate' ) ) { $decomp = @gzinflate( $serial ); if( false !== $decomp ) { $serial = $decomp; } } return unserialize( $serial ); ^^ } --- *** SECOND error -- Error line 136 indicated by ^ *** Notice: Only variable references should be returned by reference in /usr2/virtualwebs/forumkatrina.org/wiki/includes/SkinTemplate.php on line 136 function decr($key, $value=1) { if ( !$this-lock($key) ) { return false; } $value = intval($value); if($value 0) $value = 0; $m = false; ^^^ if( ($n = $this-get($key)) !== false ) { $m = $n - $value; if($m 0) $m = 0; $this-set($key, $m); // exptime? } $this-unlock($key); return $m; } __ Thanks in advance david -- 40 yrs navigating and computing in blue waters. English Owner Captain of British Registered 60' bluewater Ketch S/V Taurus. Currently in San Diego, CA. Sailing bound for Europe via Panama Canal after completing engineroom refit. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Wikimedia - php4
Vizion wrote: Hi I have just installed wikimedia on freebsd 5.3 with php4-4.4.0. I think you mean MediaWiki (common mistake!) After starting the program after a successful installation I get the error messages shown below. There are three eror from two lines of code. I have included the relevant code. [snip] *** FIRST Error - reppeated twice: *** Notice: Only variable references should be returned by reference in /usr2/virtualwebs/forumkatrina.org/wiki/includes/ObjectCache.php on line 369 Notice: Only variable references should be returned by reference in /usr2/virtualwebs/forumkatrina.org/wiki/includes/ObjectCache.php on line 369 These are coding errors in MediaWiki (but not really bad errors, just enough for PHP to flag a notice); since it's not something you can fix entirely unless you want to trawl through all of their code, the easiest thing to do is change error_reporting in your php.ini file so it looks like this: error_reporting = E_ALL ~E_NOTICE which means show all errors except notices. -- Jasper Bryant-Greene Freelance web developer http://jasper.bryant-greene.name/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Wikimedia - php4
On Tuesday 20 September 2005 19:26, the author Vizion contributed to the dialogue on- [PHP] Wikimedia - php4: Hi I have just installed wikimedia on freebsd 5.3 with php4-4.4.0. After starting the program after a successful installation I get the error messages shown below. There are three eror from two lines of code. I have included the relevant code. Having just started to learn php, I am not competent to know how to set about solving this. Does anyone here have any idea what may be wrong or do you happen to know of a suitable forum or mailing list that could be helpful Thanks in advance david -- Errors from php4.log *** FIRST Error - reppeated twice: *** Notice: Only variable references should be returned by reference in /usr2/virtualwebs/forumkatrina.org/wiki/includes/ObjectCache.php on line 369 Notice: Only variable references should be returned by reference in /usr2/virtualwebs/forumkatrina.org/wiki/includes/ObjectCache.php on line 369 Line 369 indicated by ^^^ - function _unserialize( $serial ) { if( function_exists( 'gzinflate' ) ) { $decomp = @gzinflate( $serial ); if( false !== $decomp ) { $serial = $decomp; } } return unserialize( $serial ); ^^ } --- *** SECOND error -- Error line 136 indicated by ^ *** Notice: Only variable references should be returned by reference in /usr2/virtualwebs/forumkatrina.org/wiki/includes/SkinTemplate.php on line 136 Sorry I inserted the wrong source code - this is the correct code: /** * Create the template engine object; we feed it a bunch of data * and eventually it spits out some HTML. Should have interface * roughly equivalent to PHPTAL 0.7. * * @param string $callback (or file) * @param string $repository subdirectory where we keep template files * @param string $cache_dir * @return object * @access private */ function setupTemplate( $classname, $repository=false, $cache_dir=false ) { return new $classname(); ^^ } __ Thanks in advance david -- 40 yrs navigating and computing in blue waters. English Owner Captain of British Registered 60' bluewater Ketch S/V Taurus. Currently in San Diego, CA. Sailing bound for Europe via Panama Canal after completing engineroom refit. -- 40 yrs navigating and computing in blue waters. English Owner Captain of British Registered 60' bluewater Ketch S/V Taurus. Currently in San Diego, CA. Sailing bound for Europe via Panama Canal after completing engineroom refit. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Wikimedia - php4
On Tuesday 20 September 2005 19:37, the author Jasper Bryant-Greene contributed to the dialogue on- Re: [PHP] Wikimedia - php4: Vizion wrote: Hi I have just installed wikimedia on freebsd 5.3 with php4-4.4.0. I think you mean MediaWiki (common mistake!) After starting the program after a successful installation I get the error messages shown below. There are three eror from two lines of code. I have included the relevant code. [snip] *** FIRST Error - reppeated twice: *** Notice: Only variable references should be returned by reference in /usr2/virtualwebs/forumkatrina.org/wiki/includes/ObjectCache.php on line 369 Notice: Only variable references should be returned by reference in /usr2/virtualwebs/forumkatrina.org/wiki/includes/ObjectCache.php on line 369 These are coding errors in MediaWiki (but not really bad errors, just enough for PHP to flag a notice); since it's not something you can fix entirely unless you want to trawl through all of their code, the easiest thing to do is change error_reporting in your php.ini file so it looks like this: error_reporting = E_ALL ~E_NOTICE which means show all errors except notices. You are fast!! Thanks very much for that -- OK - You replied before you will have got my correction -- but I guess your solution will work in any case!! Thanks again -- Jasper Bryant-Greene Freelance web developer http://jasper.bryant-greene.name/ -- 40 yrs navigating and computing in blue waters. English Owner Captain of British Registered 60' bluewater Ketch S/V Taurus. Currently in San Diego, CA. Sailing bound for Europe via Panama Canal after completing engineroom refit. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] losing session data with cross-site scripting
Hey folks - I have a php site on a production server. The production server doesn't have the spell libraries, and rather than migrate the site, we setup spell checking functions on the development site, and shuttled the users back and forth with specially crafted get links and forms. The POST form or GET link on the production site contains the string to be spellchecked. Once the user is at the development site, the string is spellcheck, and corrected if necessary. The development site checks the http referrer to make sure it's not just anybody, and the only thing it does is spell checking, anyway. After the spell checking is done, we then create links that bring the user back to the development site. On the development site, I have an include at the beginning of each page that checks for a session, and either takes them to the proper page, or throws an error if they are not on the login page and have no session. Most of the time, no problem. When a user is returning from the production site, their session is still set when they load the page on the production server, and they get the appropriate page. However, for a few users, they are somehow losing session data, and they get the error when they try to return from the development server. What is happening? Is is some kind of security setting on the browser? These are remote users and I can't go and inspect their computers. I will have to communicate by email or phone with them. Steve Lfevre -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] losing session data with cross-site scripting
Steve Lefevre wrote: I have a php site on a production server. The production server doesn't have the spell libraries, and rather than migrate the site, we setup spell checking functions on the development site, and shuttled the users back and forth with specially crafted get links and forms. The POST form or GET link on the production site contains the string to be spellchecked. Once the user is at the development site, the string is spellcheck, and corrected if necessary. The development site checks the http referrer to make sure it's not just anybody, and the only thing it does is spell checking, anyway. Many users disable or set their browsers to spoof referrer headers. This isn't a good thing to rely on and it may well be causing your problem. -- Jasper Bryant-Greene Freelance web developer http://jasper.bryant-greene.name/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Wikimedia - php4
Vizion wrote: Notice: Only variable references should be returned by reference in /usr2/virtualwebs/forumkatrina.org/wiki/includes/ObjectCache.php on line 369 Notice: Only variable references should be returned by reference in /usr2/virtualwebs/forumkatrina.org/wiki/includes/ObjectCache.php on line 369 Line 369 indicated by ^^^ - function _unserialize( $serial ) { if( function_exists( 'gzinflate' ) ) { $decomp = @gzinflate( $serial ); if( false !== $decomp ) { $serial = $decomp; } } return unserialize( $serial ); ^^ } A pretty standard case of someone not really understanding references in PHP. There is no need for this function to return a reference. They are likely doing it to try to avoid a copy, but no copy will be made in the standard return by value case. Simply remove the from the function definition to get rid of this notice. --- *** SECOND error -- Error line 136 indicated by ^ *** Notice: Only variable references should be returned by reference in /usr2/virtualwebs/forumkatrina.org/wiki/includes/SkinTemplate.php on line 136 function decr($key, $value=1) { if ( !$this-lock($key) ) { return false; } $value = intval($value); if($value 0) $value = 0; $m = false; ^^^ if( ($n = $this-get($key)) !== false ) { $m = $n - $value; if($m 0) $m = 0; $this-set($key, $m); // exptime? } $this-unlock($key); return $m; } Are you sure you have the right code snippet here? That's not a return line and I see no references there. -Rasmus -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Wikimedia - php4
Vizion wrote: function setupTemplate( $classname, $repository=false, $cache_dir=false ) { return new $classname(); ^^ } Is that really all they have in that function? It seems rather useless to me. Why call a function just to instantiate a class like that? Regardless, here it is trying to create a reference to a temp var. Basically PHP will ignore the reference here, and it should work, but you are getting a notice because the reference is being discarded. Either drop the reference from the function definition or do: $class = new $classname(); return $class; And for PHP5 you can just drop all references related to objects and it will do the right thing. -Rasmus -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Wikimedia - php4
On Wed, 2005-09-21 at 00:58, Rasmus Lerdorf wrote: And for PHP5 you can just drop all references related to objects and it will do the right thing. Eeeek, that's not entirely true. Sometimes you want a real reference to an object even in PHP5 :/ Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Wikimedia - php4
Robert Cummings wrote: On Wed, 2005-09-21 at 00:58, Rasmus Lerdorf wrote: And for PHP5 you can just drop all references related to objects and it will do the right thing. Eeeek, that's not entirely true. Sometimes you want a real reference to an object even in PHP5 :/ $a = new foo(); Will create a reference to the object. $b = $a; Now you have 2 references to the same object. For any sort of normal use, you never need to explicitly create references to objects in PHP 5. -Rasmus -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Wikimedia - php4
On Wed, 2005-09-21 at 01:08, Rasmus Lerdorf wrote: Robert Cummings wrote: On Wed, 2005-09-21 at 00:58, Rasmus Lerdorf wrote: And for PHP5 you can just drop all references related to objects and it will do the right thing. Eeeek, that's not entirely true. Sometimes you want a real reference to an object even in PHP5 :/ $a = new foo(); Will create a reference to the object. $b = $a; Now you have 2 references to the same object. For any sort of normal use, you never need to explicitly create references to objects in PHP 5. I think you mean novice use. There are certainly times when assigning an object to a variable I want all the values currently referring to that object to see the update and not just the variable being assigned to. I understand that objects in PHP5 are passed by reference under normal assignment, but it's a copy of a reference and not a reference to a reference. Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Wikimedia - php4
On Tuesday 20 September 2005 22:14, the author Robert Cummings contributed to the dialogue on- Re: [PHP] Wikimedia - php4: On Wed, 2005-09-21 at 01:08, Rasmus Lerdorf wrote: Robert Cummings wrote: On Wed, 2005-09-21 at 00:58, Rasmus Lerdorf wrote: And for PHP5 you can just drop all references related to objects and it will do the right thing. Eeeek, that's not entirely true. Sometimes you want a real reference to an object even in PHP5 :/ $a = new foo(); Will create a reference to the object. $b = $a; Now you have 2 references to the same object. For any sort of normal use, you never need to explicitly create references to objects in PHP 5. I think you mean novice use. There are certainly times when assigning an object to a variable I want all the values currently referring to that object to see the update and not just the variable being assigned to. I understand that objects in PHP5 are passed by reference under normal assignment, but it's a copy of a reference and not a reference to a reference. Cheers, Rob. -- `' Thank you all so much.. Now I do not get the notices and I almost understand what you guys are saying :-) That makes it a good day!! chuckles david -- 40 yrs navigating and computing in blue waters. English Owner Captain of British Registered 60' bluewater Ketch S/V Taurus. Currently in San Diego, CA. Sailing bound for Europe via Panama Canal after completing engineroom refit. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Wikimedia - php4
Robert Cummings wrote: I think you mean novice use. There are certainly times when assigning an object to a variable I want all the values currently referring to that object to see the update and not just the variable being assigned to. I understand that objects in PHP5 are passed by reference under normal assignment, but it's a copy of a reference and not a reference to a reference. I am not sure I would call it novice use. Normally you simply want to manipulate the object itself. As in: class foo { public $prop = 1; } $a = new foo(); $b = $a; $b-prop++; echo $a-prop; This will of course output 2. Manipulating the object through any of its references will be reflected in all the others as there is just one object here. -Rasmus -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Wikimedia - php4
On Wed, 2005-09-21 at 01:20, Rasmus Lerdorf wrote: Robert Cummings wrote: I think you mean novice use. There are certainly times when assigning an object to a variable I want all the values currently referring to that object to see the update and not just the variable being assigned to. I understand that objects in PHP5 are passed by reference under normal assignment, but it's a copy of a reference and not a reference to a reference. I am not sure I would call it novice use. Normally you simply want to manipulate the object itself. As in: class foo { public $prop = 1; } $a = new foo(); $b = $a; $b-prop++; echo $a-prop; This will of course output 2. Manipulating the object through any of its references will be reflected in all the others as there is just one object here. Absolutely, but that's the object's properties, but sometimes when assigning a new object, you want all references to the previous object to also be updated. Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php