Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > [2564] "บักกิเลส" bug-gy/less ตั้งแต่ งวดที่ 3/2 → ...



 

[2564] "บักกิเลส" bug-gy/less ตั้งแต่ งวดที่ 3/2 → ...

 



Topic : 136268



โพสกระทู้ ( 296 )
บทความ ( 0 )



สถานะออฟไลน์




Quote:
ปริศนา buggy งวดที่ 3 ประจำวันที่ 16 กรกฎาคม 2564
มีวิธีแก้ปัญหามากกว่าหนึ่ง


3.1
buggy
first seen: Array to string conversion Undefined variable next: no bug, but full array(remove it) last: wrong result value from first "echo" (do fix it)


Code (PHP)
$vars = get_defined_vars();
$g = array_keys($GLOBALS);

$a = [["z" => "x", "x" => ["x", "y", "z"]], 1];
$b = "y";
$c = "z";

${array_values($a[0])[1]} = 2;
$$b = 3;
$$c = 5;

echo ($x+$y+$z) / count($a, 1);
$vars = array_diff(get_defined_vars(), $vars);
print_r($vars);



Expected output
2 Array ( [a] => Array ( [0] => Array ( [z] => x [x] => Array ( [0] => x [1] => y [2] => z ) ) [1] => 1 ) [บี] => y [c] => z [x] => 2 [y] => 3 [z] => 5 )


*** ผลลัพธ์ที่ถูกต้อง... แทน "บี" ด้วย "b" ใช้วิธีเลี่ยงเพราะไปซ้ำกับ bbcode ตัวหนา ***




3.2
สร้าง mutator method ให้สอดคล้องกับ interface (Interface1)
สามารถกำหนดและแสดงค่า private property ($vars) จากคลาส A
แบบ "method chaining"

buggy
1. Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR), expecting ',' or ';' 2. Cannot instantiate abstract class 3. Class ... contains 1 abstract method and must therefore be declared abstract or implement the remaining methods 4. Undefined property: ... 5. Undefined index: ... 6. Call to a member function get() on null ... (ไม่จำเป็นต้องเจอทุกข้อ)


Code (PHP)
interface Interface1
{
    public function set($name, $var);
    public function get($name);
}

abstract class A implements Interface1
{
    private $vars = [];
  
    public function set($name, $var)
    {
        $this->vars[$name] = $var;
    }
}

echo new A->$var;





3.3
ปรับเปลี่ยน 3.2 ให้สามารถกำหนดและแสดงค่า private property ($vars)
จาก class A ได้ โดยไม่ต้องสร้าง object และไม่จำเป็นต้องเรียกแบบ "method chaining"

buggy
1. Cannot make non static method Interface1::set() static in class A 2. Using $this when not in object context 3. Access to undeclared static property ... และอื่นๆ ตามที่เห็น






Quote:
หวย bugless งวดที่ 2 ประจำวันที่ 16 กรกฎาคม 2564
https://www.thaicreate.com/php/forum/136238.html



Az-Steg

bugless 2






Quote:
ตั้งแต่ bugless งวดที่ 2 เป็นต้นไป จะใช้เทคโนโลยีการจัดเก็บข้อมูลแบบ 2 in 1 (สะดวกอันไหนใช้อันนั้น)

1. Image Processing (Aztec) สแกนหรือใช้ online tools ในการถอด url ไปยัง bugless encrypted (myCompiler)

2. Steganography ใช้บริการ JS library ของ stylesuxx
ขั้นตอนการถอดข้อความซ่อนด้วย Steganography
(1) นำรูป Az-Steg ไป decode ที่ https://stylesuxx.github.io/steganography/ https://www.w3schools.com/code/tryit.asp?filename=GSEQ4BWMLE8O (สำรอง) *(2) ข้อความ unicode จะอยู่ในรูป HTML Entities ถ้าต้องการดูแบบ (true) original content ให้แปลงจาก Unicode Entities เป็น Text ก่อน https://www.online-toolz.com/tools/unicode-html-entities-convertor.php ข้อ (2) ไม่จำเป็น





(ทำไปทำมาเริ่มขี้เกียจละ...)



Tag : PHP









ประวัติการแก้ไข
2021-07-16 14:23:26
2021-07-16 14:26:27
2021-07-16 14:27:14
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2021-07-16 14:10:45 By : TheGreatGod_of_Death View : 528 Reply : 5
 

 

No. 1



โพสกระทู้ ( 296 )
บทความ ( 0 )



สถานะออฟไลน์


Quote:
ปริศนา buggy งวดที่ 4 ประจำวันที่ 1 สิงหาคม 2564
(เริ่มตั้งแต่งวดที่ 4 ส่วนที่เป็น bug/error จะถูกละไว้ในฐานปฏิบัติการทดลอง)


4.1
$z = range(1, 5);
$y = function ($y) {return $y**$y;};
$fn = function ($x, $y, $z) {
    return $x + $y($z);
};
var_export(array_map($fn, 3, $y, $z));


output
array ( 0 => 4, 1 => 7, 2 => 30, 3 => 259, 4 => 3128, )





4.2
เรียกใช้ private property($variable) ของ MyClass โดยไม่แก้ไขคลาส

Code (PHP)
// DON'T TOUCH "MyClass" class
class MyClass {
    private static $variable = 'I am private variable!';
}
echo MyClass::variable;


output
I am private variable!





4.3 (ไม่แสดง bug/error)
ลดการใช้งานหน่วยความจำ (Memory Consumption Reduction)
จาก >1MB ทำให้เหลือ <1KB

Code (PHP)
$before = memory_get_usage();
$time_start = microtime(true);

function render($number) {
	$r = [];
	for ($i = 0; $i < $number; $i++) {
    	$r["name_$i"] = "description_$i";
    }
    return $r;
}

function getRender($render, $key) {
	foreach($render as $k=>$v) {
		if ($k == $key) {
	    	return $v;
	    }
	}
}

$render = render(10000);
echo $render['name_9999'];

$after = memory_get_usage();
echo "<hr>memory usage: ", number_format($after - $before), " bytes<br>";
echo 'execution time: ' . (microtime(true) - $time_start) . ' seconds';






Quote:
หวย bugless งวดที่ 3 ประจำวันที่ 1 สิงหาคม 2564


Bugless 3
Bugless 3









ประวัติการแก้ไข
2021-08-01 13:50:57
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-08-01 13:49:27 By : TheGreatGod_of_Death
 


 
ความรู้นี่ไม่มีที่สิ้นสุดเลยครับ ">
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-08-13 20:25:55 By : nobody001
 

 

No. 3



โพสกระทู้ ( 296 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 2 เขียนโดย : nobody001 เมื่อวันที่ 2021-08-13 20:25:55
รายละเอียดของการตอบ ::
ทำไมไม่ศึกษา SEO ให้เว็บติด search ดีๆ
ดีกว่ามาซ่อนลิงค์โฆษณาตามเว็บอื่น

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-08-14 13:02:15 By : TheGreatGod_of_Death
 


 

No. 4



โพสกระทู้ ( 296 )
บทความ ( 0 )



สถานะออฟไลน์


Quote:
ปริศนา buggy งวดที่ 5 ประจำวันที่ 16 สิงหาคม 2564


5.1
จงหาวิธีเรียกใช้ตัวแปร (variable) ที่มีชื่อซ้ำกันจากต่าง namespace
(โดยไม่ใช้ const)

Code (PHP)
namespace ns1 {
	$x = 1;
}

namespace ns2 {
	$x = 2;
}

namespace {
	$x = 3;
    echo ns1\$x, "<br>";
	echo ns2\$x, "<br>";
    echo $x;
}


output:
1 2 3





5.2
จงแก้ปัญหาการ extends class พร้อมกันมากกว่า 1 class จาก namespace อื่น

Code (PHP)
namespace FOO;

class Hello {
    public function sayHello() {
        echo 'Hello ';
    }
}

class World {
    public function sayWorld() {
        echo 'World';
    }
}

namespace BAR;

class MyHelloWorld extends \FOO\{Hello, World} {
    public function sayExclamationMark() {
        echo '!';
    }
}

$o = new MyHelloWorld();
$o->sayHello();
$o->sayWorld();
$o->sayExclamationMark();


output:
Hello World!





5.3
จงทำให้ฟังก์ชัน sum() จาก namespace "ns2" สามารถเรียกใช้จาก global space
โดยรับรอง argument 2 ประเภท คือ optional array และ null
ถ้าใส่ parameter เป็น array ให้ return ค่าด้วย
ผลบวกของผลรวมค่าของสมาชิกทุกตัวใน array นี้กับค่าคงที่จาก namespace "ns1"
แล้วหารค่าคงที่จาก namespace "ns2" ...พร้อมใส่เครื่องหมาย % ปิดท้ายผลคำนวณ

Code (PHP)
namespace ns1 {
	const x = 100;
}

namespace ns2 {
	use ns1\x as n100;
	const x = 2;
    function sum(?array $a=[x]) : string {
    	(string)yield (n100 + sum($a)) / x . '%';
    }
}

namespace {
	use ns2\sum;
	echo sum(), "<br>";
    echo sum(null), "<br>";
    echo sum([1, 2, 3]);
}


output:
51% 50% 53%






Quote:
หวย bugless งวดที่ 4 ประจำวันที่ 16 สิงหาคม 2564


bugless 4
Bugless 4






Quote:
Buggy 5 เป็นงวดสุดท้ายจากผม (TGGoD)
ซึ่งครอบคลุมเนื้อหาพื้นฐานเท่าที่จำเป็น
หากผู้ใดสามารถแก้ปัญหาได้เองหรือทำความเข้าใจจาก *less
ทั้ง 15 จาก 5 งวด (ไม่ ||) การันตีว่าจะสามารถสร้างเฟรมเวิร์กเองได้

...แต่อาจไม่ใช่งวดสุดท้าย
รอคนมารับไม้ต่อ


ส่วน Bugless 5 จะลงวันที่ 1 ก.ย. ศกนี้
จะมาพร้อมกับ Bugno (Buggy no-Bugless) ...ปิดขวัญถุง

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-08-16 11:18:09 By : TheGreatGod_of_Death
 


 

No. 5



โพสกระทู้ ( 296 )
บทความ ( 0 )



สถานะออฟไลน์


Quote:
หวย bugless งวดที่ 5 ประจำวันที่ 9 กันยายน 2564
(Last bugless by TGGoD)


Bugless 5
Bugless 5






Quote:
Bugno
(Intermediate-Advanced)


1. นำความรู้พื้นฐานที่ได้จากการศึกษาค้นคว้าเพื่อแก้ปัญหาปริศนา buggy ทั้ง 5
มาต่อยอด โดยสร้างเฟรมเวิร์กขนาดจิ๋ว (tiny-framework) เป็นของตัวเอง

2. ลองพัฒนาเฟรมเวิร์กที่ได้จากข้อ 1. ให้เป็น core-framework
ที่รองรับ Add-ons/Plugins ด้วยเทคนิค Hook

In computer programming, the term hooking covers a range of techniques used to alter or augment the behaviour of an operating system, of applications, or of other software components by intercepting function calls or messages or events passed between software components. Code that handles such intercepted function calls, events or messages is called a hook.

ตัวอย่าง PHP ที่ใช้ Hook เช่น Actions และ Filters ใน WordPress เป็นต้น

3. ประยุกต์ข้อ 1. และ/หรือ 2. ให้มีกลไกการขับเคลื่อนแบบ IoC/DI Container
(ประกอบด้วย Inversion of control และ/หรือ Dependency Injection)

https://www.martinfowler.com/articles/injection.html

ตัวอย่าง PHP framework ที่ใช้ IoC/DI Container ได้แก่ Laravel เป็นต้น

4. ต่อยอด 1.-3. เป็น micro-framework

5. ดัดแปลง framework ในข้อ 4. ให้อยู่ในรูป Dynamic Library หรือที่รู้จักกันในนาม
PHP extension





พึ่งสังเกตเห็นว่าวันนี้ เลขวันที่+เดือน เป็นเลขมงคลแห่งปี
เลยแวะมาอัปเดต bugless งวดสุดท้าย
จะได้ก้าวหน้า ก้าวผ่านทุกปัญหาไปได้กันทุกคน

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-09-09 22:24:02 By : TheGreatGod_of_Death
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : [2564] "บักกิเลส" bug-gy/less ตั้งแต่ งวดที่ 3/2 → ...
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 01
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่