Myitkyina Online
ၿမစ္ၾကီးနားအြန္လိုင္းဖိုရမ္မွၾကိဳဆိုပါတယ္..။
အသင္းသားမၿဖစ္ေသးလွ်င္ Register ကိုႏိုပ္ၿပီးform ၿဖည့္ေပးပါ..။
ေနာက္..မိမိဂ်ီေမးလ္ကိုဖြင့္ၿပီး..အတည္ၿပဳေပးပါ..။
အသင္း၀င္ၿပီးပါက.. login ကိုႏိုပ္ၿပီး၀င္ပါ..။
ေက်းဇူးတင္ပါတယ္..။

ၿမစ္ၾကီးနားအြန္လိုင္းဖိုရမ္ႏွင္ ့မိသဟာယ




Web Developer မ်ား Websites ေရးဆဲြရန္ ေခတ္ဆံုးၿပီးလားဟု Dr Ddob ကေၿပာၾကားခဲ႕

View previous topic View next topic Go down

Web Developer မ်ား Websites ေရးဆဲြရန္ ေခတ္ဆံုးၿပီးလားဟု Dr Ddob ကေၿပာၾကားခဲ႕

Post  lynaungkyaw on Thu Oct 07, 2010 7:30 pm

PHP language ၿဖင္႕ေရးေသာ Websites မ်ား Error ႏွင္႕ၾကံဳေတြေနသၿဖင္႕ Blogger အခက္ေတြ႕ေနၾကရပါသည္။
ထို႕ေၾကာင္႕ 0ctober 1 ရက္ေန႕တြင္ ယင္း PHP HTs 2.0.1 ကိုၿပန္လည္ၿပဳၿပင္မည္ဟု Professor Dr.John Vesee က Bestel web ကိုေၿပာၾကားခဲ႔ေၾကာင္းသိရွိရပါသည္။ထို႕ေၾကာင္႕ၿဖစ္ေနေသာ Error မ်ားမွာ ေအာက္ပါပံုစံၿဖစ္ေနသၿဖင္႕အခက္ေတြ႕ေနၾကရပါသည္။

<?php

// Turn off all error reporting
error_reporting(0);

// Report simple running errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);

// Reporting E_NOTICE can be good too (to report uninitialized
// variables or catch variable name misspellings ...)
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

// Report all errors except E_NOTICE
// This is the default value set in php.ini
error_reporting(E_ALL ^ E_NOTICE);

// Report all PHP errors (see changelog)
error_reporting(E_ALL);

// Report all PHP errors
error_reporting(-1);

// Same as error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);
<?php
function get_debug_print_backtrace($traces_to_ignore = 1){
$traces = debug_backtrace();
$ret = array();
foreach($traces as $i => $call){
if ($i < $traces_to_ignore ) {
continue;
}

$object = '';
if (isset($call['class'])) {
$object = $call['class'].$call['type'];
if (is_array($call['args'])) {
foreach ($call['args'] as &$arg) {
get_arg($arg);
}
}
}

$ret[] = '#'.str_pad($i - $traces_to_ignore, 3, ' ')
.$object.$call['function'].'('.implode(', ', $call['args'])
.') called at ['.$call['file'].':'.$call['line'].']';
}

return implode("\n",$ret);
}

function get_arg(&$arg) {
if (is_object($arg)) {
$arr = (array)$arg;
$args = array();
foreach($arr as $key => $value) {
if (strpos($key, chr(0)) !== false) {
$key = ''; // Private variable found
}
$args[] = '['.$key.'] => '.get_arg($value);
}

$arg = get_class($arg) . ' Object ('.implode(',', $args).')';
}
}
?>
bishop
28-Jul-2009 08:20
Another way to manipulate and print a backtrace, without using output buffering:

<?php
// print backtrace, getting rid of repeated absolute path on each file
$e = new Exception();
print_r(str_replace('/path/to/code/', '', $e->getTraceAsString()));
?>
bradley dot giesbrecht at gmail dot com
14-Jan-2009 12:51
I was using the function by dany dot dylan at gmail dot com and found that preg_replace had string length limits. So here is yet another output format function.

<?php
if ( !function_exists ( "mydie" ) ) {
function mydie ( ) { $this_file = __FILE__ ; $this_line = __LINE__ ;
$buffer = array ( ) ;
$trace_calls = "" ;
ob_start ( ) ;
debug_print_backtrace ( ) ;
$buffer[ "0" ] = ob_get_contents ( ) ;
ob_end_clean ( ) ;
$buffer[ "0" ] = array_slice ( explode ( "#" , $buffer[ "0" ] ) , 1 , -1 , false ) ;
foreach ( $buffer[ "0" ] as $key => $value ) {
$value = explode ( ") called at [" , $value ) ;
if ( $key == 0 ) {
$value[ "0" ] = "0 " . __FUNCTION__ . "(see above vars)" ;
}
$trace_calls .= "#" . implode ( ")\n\tcalled at [" , $value ) ;
}
unset ( $buffer , $key , $value ) ;
echo "<pre>function " . __FUNCTION__ . " lives here:{$this_file}:{$this_line}</pre>" ;
echo ( "<pre>" . print_r( func_get_args ( ) , true ) . "</pre>" ) ;
if ( $trace_calls == "" ) $trace_calls = "No functions were called." ;
echo ( "<pre>" . $trace_calls . "</pre>" ) ;
die ;
}
}
function a ( ) {
b ( func_get_args ( ) , 2 ) ;
}
function b ( ) {
c ( func_get_args ( ) , 3 ) ;
}
function c ( ) {
mydie ( func_get_args ( ) , 4 ) ;
}
a ( 1 ) ;
?>

## outputs
function mydie lives here:/path/file.php:4
Array
(
[0] => Array
(
[0] => Array
(
[0] => Array
(
[0] => 1
)

[1] => 2
)

[1] => 3
)

[1] => 4
)
#0 mydie(see above vars))
called at [/path/file.php:54]
#1 c(Array ([0] => Array ([0] => 1),[1] => 2), 3)
called at [/path/file.php:49]
#2 b(Array ([0] => 1), 2)
called at [/path/file.php:43]
dany dot dylan at gmail dot com
11-Nov-2008 05:51
I like the output of debug_print_backtrace() but I sometimes want it as a string.

bortuzar's solution to use output buffering is great, but I'd like to factorize that into a function. Doing that however always results in whatever function name I use appearing at the top of the stack which is redundant.

Below is my noddy (simple) solution. If you don't care for renumbering the call stack, omit the second preg_replace().

<?php
function debug_string_backtrace() {
ob_start();
debug_print_backtrace();
$trace = ob_get_contents();
ob_end_clean();

// Remove first item from backtrace as it's this function which
// is redundant.
$trace = preg_replace ('/^#0\s+' . __FUNCTION__ . "[^\n]*\n/", '', $trace, 1);

// Renumber backtrace items.
$trace = preg_replace ('/^#(\d+)/me', ''#' . ($1 - 1)', $trace);

return $trace;
}
?>

lynaungkyaw
မူၾကိဳအဆင့္
မူၾကိဳအဆင့္

ေရးသားခ်က္မ်ား : 4
Start Date: : 2010-07-11

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum