Difference between revisions of "Sven/PHP"
(http://www.php.net/manual/en/ref.apd.php) |
(Major rewrite) |
||
Line 1: | Line 1: | ||
+ | ==PHP errors== | ||
+ | To see PHP errors, add this to the very top of <tt>[[MW:Manual:LocalSettings.php|LocalSettings.php]]</tt>: | ||
+ | {{code| | ||
+ | <php> | ||
+ | error_reporting(E_ALL); | ||
+ | ini_set("display_errors", 1); | ||
+ | </php> | ||
+ | }} | ||
+ | |||
+ | |||
==Debugging PHP== | ==Debugging PHP== | ||
+ | The idea is to debug sections of computer code which are under executional focus, this is considerably easier in an OOP paradigm than a procedural one which uses encapsulation. The class provies certain methods and properties to the code that uses the objects, so outside code does not directly access the data structures of those objects, they do so through the interface. | ||
+ | |||
{{Info|In MediaWiki there is a profiler that can be set, see [[MW:How to debug]].}} | {{Info|In MediaWiki there is a profiler that can be set, see [[MW:How to debug]].}} | ||
Line 25: | Line 37: | ||
outputs; | outputs; | ||
− | + | {{code| | |
− | + | <php> | |
− | + | Array | |
− | + | ( | |
− | ;) | + | [name] => Fred |
+ | [age] => 35 | ||
+ | ) | ||
+ | </php> | ||
+ | }} | ||
+ | |||
+ | ====Logging information to file=== | ||
+ | From [[Sven/Notes]], [[Extension:Fasta.php]]; | ||
+ | {{code| | ||
+ | <php> | ||
+ | # Logging to an article from within the MW environment | ||
+ | function logAdd($article,$msg) { | ||
+ | $ts = $GLOBALS['wgLang']->timeanddate(wfTimestampNow(),true); | ||
+ | $la = new Article(Title::newFromText($article)); | ||
+ | $la->quickEdit($la->getContent()."\n*$ts: $msg"); | ||
+ | } | ||
+ | |||
+ | # Logging to a file | ||
+ | function logFile($file, $msg) { | ||
+ | $fh = fopen($file,'a'); | ||
+ | $ts = $GLOBALS['wgLang']->timeanddate(wfTimestampNow(),true); | ||
+ | if(is_array($msg)) $msg = print_r($msg, true); | ||
+ | fwrite($fh, "\n$ts: $msg"); | ||
+ | # $ts = date("Y-m-d H:i:s"); | ||
+ | # @file_put_contents($wgPayPalLog,"$ts $text\n",FILE_APPEND); | ||
+ | } | ||
+ | </php> | ||
+ | }} | ||
==Introspection== | ==Introspection== | ||
{{Info|<br /> | {{Info|<br /> | ||
− | *Pages 147-153 ([http://www.oreilly.com/catalog/progphp/ Programming php]) for introspection functions | + | *See Pages 147-153 ([http://www.oreilly.com/catalog/progphp/ Programming php]) for a list of introspection functions in php. |
*http://www.php.net/manual/en/ref.classobj.php | *http://www.php.net/manual/en/ref.classobj.php | ||
}} | }} | ||
Line 46: | Line 85: | ||
} | } | ||
</php> | </php> | ||
+ | ;PHP Help doumentation | ||
*[http://www.php.net/get_declared_classes get_declared_classes] | *[http://www.php.net/get_declared_classes get_declared_classes] | ||
*[http://www.php.net/get_class_methods get_class_methods] | *[http://www.php.net/get_class_methods get_class_methods] | ||
Line 63: | Line 103: | ||
return(); | return(); | ||
} | } | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
</php> | </php> | ||
}} | }} | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
==MediaWiki profiler== | ==MediaWiki profiler== | ||
Line 149: | Line 160: | ||
;Debugging | ;Debugging | ||
*[[MediaWiki code snippets]] | *[[MediaWiki code snippets]] | ||
− | *[[ | + | *[[Wikipedia:Debugging]] |
*[[MW:How to become a MediaWiki hacker]] | *[[MW:How to become a MediaWiki hacker]] | ||
*[[MW:Extensions_FAQ]] | *[[MW:Extensions_FAQ]] | ||
− | ; | + | ;PHP Documentation |
*[http://www.php.net/manual/en/language.oop5.php Classes and Objects (PHP 5)] | *[http://www.php.net/manual/en/language.oop5.php Classes and Objects (PHP 5)] | ||
+ | *[http://www.php.net/manual/en/ref.classobj.php OOP documentation] | ||
*[http://www.php.net/manual/en/ref.classobj.php Introspection:Class/Object Functions] | *[http://www.php.net/manual/en/ref.classobj.php Introspection:Class/Object Functions] | ||
*[http://www.php.net/manual/en/language.oop5.paamayim-nekudotayim.php Scope Resolution Operator (::)] | *[http://www.php.net/manual/en/language.oop5.paamayim-nekudotayim.php Scope Resolution Operator (::)] | ||
*[http://www.php.net/manual/en/ref.apd.php Advanced php debugger] | *[http://www.php.net/manual/en/ref.apd.php Advanced php debugger] | ||
− | ;Documentation | + | |
+ | |||
+ | ;MediaWiki Documentation | ||
*[http://svn.wikimedia.org/doc/ Deoxygen MediaWiki Documentation] | *[http://svn.wikimedia.org/doc/ Deoxygen MediaWiki Documentation] | ||
*[[MW:Manual:Coding_conventions]] | *[[MW:Manual:Coding_conventions]] | ||
Line 167: | Line 181: | ||
*[[Extension:PayPal.php]] - ''currently contains debugging'' | *[[Extension:PayPal.php]] - ''currently contains debugging'' | ||
− | ;Resources | + | ;Online Resources |
− | |||
*http://en.wikibooks.org/wiki/Programming:PHP | *http://en.wikibooks.org/wiki/Programming:PHP | ||
+ | |||
+ | |||
+ | [[Category:MediaWiki]] | ||
+ | [[Category:Examples/PHP]] |
Revision as of 23:18, 13 April 2008
Contents
PHP errors
To see PHP errors, add this to the very top of LocalSettings.php:
Debugging PHP
The idea is to debug sections of computer code which are under executional focus, this is considerably easier in an OOP paradigm than a procedural one which uses encapsulation. The class provies certain methods and properties to the code that uses the objects, so outside code does not directly access the data structures of those objects, they do so through the interface.
Debuggers generally use a W:Stack trace. This can be approximated by using print and die statements in sections of code. The combination of print_r and func_get_args allows you to return an array of args that a function was called with;
Casting an object of an array builds an array of the properties, mapping property names to values. e.g.
outputs;
=Logging information to file
From Sven/Notes, Extension:Fasta.php;
Introspection
MediaWiki profiler
The article how to debug MediaWiki provides information on setting up the profiler by adding the globals to your LocalSettings.php file;
However if you include in an extension;
there seems to be no output in the generated log file.
See also
- Debugging
- PHP Documentation
- Classes and Objects (PHP 5)
- OOP documentation
- Introspection:Class/Object Functions
- Scope Resolution Operator (::)
- Advanced php debugger
- MediaWiki Documentation
- Deoxygen MediaWiki Documentation
- MW:Manual:Coding_conventions
- MW:Manual:Extensions
- MW:Manual:$wgExtensionFunctions
- Extensions
- Extension:PayPal.php - currently contains debugging
- Online Resources