• PHP

    Trait – Mixin in PHP? – PART 2

    Dưới đây là phần 2 (và cũng là phần cuối) của series “Trait – Mixin trong PHP”. Ở phần này chúng ta sẽ đi sâu vào cách xử lý xung đột, mở rộng khả năng của Trait và các ví dụ thực tiễn. Mời các bạn xem lại phần 1 tại đây: https://dangnh.cf/2018/06/01/trait-mixin-in-php/ 1. Giải quyết xung đột giữa các Trait Khi một class use nhiều trait và có phương thức trùng tên, PHP sẽ báo lỗi. Để tránh, ta dùng hai từ khóa: 1.1. insteadof Chọn phương thức của trait này thay vì của trait kia: 1.2. as Đổi…

  • PHP

    Service Container & DI “sành điệu” với Laravel

    Hi, long time no see 😀 Laravel là một framework nổi tiếng nhất trong cộng đồng PHP, 1 phần là vì cấu trúc tuyệt vời của nó. Khi nói đến architectural concepts của Laravel, không thể không nhắc tới Service Container. Khi bạn đụng đến 1 bài toán lớn hơn, cần sử dụng nhiều services, dependencies… thì bạn sẽ cần hiểu và sử dụng được Service Container.

  • PHP - Web development

    Trait – Mixin in PHP?

    Hi guys 🙂 Như các bạn có lẽ đã biết, PHP là 1 ngôn ngữ single inheritance, tức là nó sẽ có 1 số nhược điểm như: Mất thời gian & công sức khi tìm hiểu/chạy hệ thống. Ví dụ: 1 class có 10 levels các class cha, thì về cơ bản nó sẽ phải chạy qua cả 10 levels đó để chạy 1 function mà nó thừa kế Class cha và class con bị ràng buộc với nhau. Tức là ta không thể tách riêng biệt 1 class nào để sử dụng được. Theo thời gian, thêm, sửa, xóa…

  • Environment - Web development

    Setup Nginx, PHP, MySQL and phpMyAdmin on macOS High Sierra

    Recently I bought a Mac and with all the curiosity, I upgraded to the newest OS which is High Sierra. I heard a lot about the ease of setting up development environment on Mac with package manager like brew Beside, I have used Linux and Windows simultaneously for almost a year, so I thought an OS based on Unix? How hard could it be? WELL I WAS DEAD WRONG! I needed Nginx, PHP 5.6, MySQL version 5.*, phpMyAdmin is optional since I can use MySQL Workbench or Navicat instead. After 2 days of burying myself in bash command, I finally…

  • PHP

    stdClass là gì? Làm thế nào để có Dynamic Properties trong PHP?

    Chào các bạn, mình là Đăng, và mình đã trở lại rồi đâyy  Nếu bạn là 1 người rất hay tò mò nghịch ngợm, giống tôi, thì chắc hẳn bạn đã từng lang thang trong core của mấy thằng PHP framework như Laravel hay Yii, và chắc cmn cú là các bạn cũng đã thấy từ khóa stdClass quanh quẩn trong đó vài lần rồi. Okay vậy bây giờ chúng ta cùng xắn tay áo lên để tìm hiểu xem nó là cái quái gì mà bọn dev khủng nó thích dùng thế nhở?

  • PHP

    What is stdClass? And Dynamic Properties in PHP?

    Well hello there, I’m back If you are a curious person, like me, you must have wandered in the core code of PHP frameworks like Laravel or Yii, and you must have seen this stdClass here and there. Now, let’s see what is that and how it helps us to code cleaner and more efficient. Okay if you came from or know even just a little Java, you’ll familiar with this concept called Dynamic Properties, to create a new object in Java somehow it’ll look like this: Well, before PHP 5.4 object’s properties must be predefined before we can set or get…

  • PHP

    Làm toán giải trí một tí nhỉ?

    Ok, chào tất cả anh em Chả là cuối tuần, ở nhà rảnh rang, trời thì se se lạnh, mũi hơi tắc, chỉ muốn co ro quấn chăn ôm laptop cho ấm. Lang thang thi cái cuộc thi lập trình của bọn Top Career gì đó :v vô tình vấp phải 1 bài test demo, mà mình thấy khá hay, nên muốn chia sẻ lên đây cho cả nhà Đề bài: A zero-indexed array A consisting of N integers is given. An equilibrium index of this array is any integer P such that 0 ≤ P < N and the…

  • HTML, CSS

    Short & accurate definition about position in CSS

    Ever since I started developing web, I've seen and used the CSS attribute so-called "position". But I'd never seem to understood what it does, I just randomize its value until I got what I needed (yeah that's stupid and ignorance). But then, one day, I realize something big, something important is missing... I feel so empty inside... DAMN I HAVE TO WRAP MY HEAD AROUND THIS "POSITION" THING! So here it hoes *goes (sorry, typo), real short and accurate. Hope this post will help some fallen angel like I used to be.