Accessing private object property from other object in PHP

Last time I wrote about Weirdest PHP construction I’ve ever seen, now I found another unusual PHP solution. PHP offers 3 visibility modifiers: private, protected and public. Private properties and methods can’t be accessed outside the object, as well as from inherited classes. With one exception… They can be accessed by other instances of the same class.

Last time I wrote about Weirdest PHP construction I’ve ever seen, now I found another unusual PHP solution. PHP offers 3 visibility modifiers: private, protected and public. Private properties and methods can’t be accessed outside the object, as well as from inherited classes. With one exception… They can be accessed by other instances of the same class.

Read more

Weirdest PHP construction I’ve ever seen

Let’s say that PHP isn’t the best, if it goes with language organisation. But thing I discovered yesterday scared me and surprised in the same moment. I know about ability to nest function in function (I even saw something implemented this way…), but didn’t know that we can call nested method like in the listing bellow. Please, don’t do this ever!

Let’s say that PHP isn’t the best, if it goes with language organisation. But thing I discovered yesterday scared me and surprised in the same moment. I know about ability to nest function in function (I even saw something implemented this way…), but didn’t know that we can call nested method like in the listing bellow. Please, don’t do this ever!

Read more

MongoDB – baza danych zorientowana dokumentowo. Czy ruch NoSQL ma sens?

Read more

Symfony sfWidgetFormSelect with disabled options

The sfWidgetFormSelect doesn’t provide ability to render disabled options. It’s rarely used feature of a HTML select element, but sometimes it could save your life 🙂 In fact, we can achieve this feature by creating our own widget, like one listed below, which inherits from sfWidgetFormSelect. This solution is inspired by problem posted on Symfony Experts.

Read more

Symfony Mixins – how to extend symfony core classes without inheritance

Symfony is very powerful PHP framework, one of the most popular in the PHP world. In big projects you should probably noticed, that there isn’t easy way to extend core classes, which aren’t returned by factories, for example actions classes. Every generated module has actions.class.php, which inherits from sfActions. What, if we want to have same method in few actions, let’s call it getCurrentDay to achieve effect listed bellow?

class defaultActions extends sfActions
{
  public function executeIndex(sfWebRequest $request)
  {
    $year = $request->getParameter('year', date('Y'));
    $this->day   = $this->getCurrentDay($year);
    $this->month = $this->getCurrentMonth($year);
  }
}
Current day is <strong>Monday 2010</strong>
The month is <strong>February</strong>
Read more

Which convention is more common „static public function” or „public static function” (based on Symfony and Doctrine)

Few minutes ago Brent Shaffer asked on the Twitter

Which is more standard, „public static function” or „static public function”?

I was curious about it, so I’ve checked which convention is used in my favourite Symfony Project. Of course, I haven’t got enough time to check it manually, class by class, so I wrote simple bash script:

egrep "^[^\*/]*static.*function" /usr/share/php/symfony/ -rioh --include=*.php | sed 's/^\s*//g' | sort | uniq  -c | sort -r

The answer  for the Symfony 1.2 was:

685 public static function
181 static public function
27 static protected function
16 protected static function
16 private static function
11 static function
2 abstract public static function

I’ve done same thing for Doctrine ORM Project

egrep "^[^\*/]*static.*function" /usr/share/php/Doctrine/lib/ -rioh --include=*.php | sed 's/^\s*//g' | sort | uniq  -c | sort -r

and the result was:

78 public static function
6 static public function
6 static protected function

Now I can tell that „public static function” is more common, and by the way I use same convention in my classes 🙂

Read more

Podsumowanie 2009 roku

Z okazji kończącego się roku, krótkie podsumowanie najchętniej czytanych przez was artykułów:

  1. O mnie – 15%
  2. TCPDF – polskie czcionki – 14%
  3. Symfony admin generator – optymalizacja zapytań do bazy dla Doctrine – 6%
  4. svn:externals – czyli jak utrzymać porządek w wersjonowanym kodzie – 3%
  5. Live events w jQuery 1.3 – 3%

Poza tym sporą oglądalność ma strona główna z oglądalnością rzedu 10%. Blog z miesiąca na miesiąc notuje coraz wyższą odwiedzalność. Jeśli jest jakiś temat, który poruszyłem, albo mogę poruszyć i jest warty rozwinięcia jako post na blogu, to proszę o sygnał w komentarzu, emailem do mnie lub poprzez twitter: twitter.com/sznapka.

Do siego roku!

Read more

Using XML and XPath in PostgreSQL database

Everybody knows, that PostgreSQL is one of the best open-source RDBMS. The keyword here is „relational” database. For most purposes relational structure is okay, but sometimes we have to store highly complicated hierarchical data. Mapping such hierarchical structure to relational tables could be a real pain. A simple solution is to use a hierarchical markup language to present our data – XML. Luckily PostgreSQL provides a data type for storing XML documents. I was very optimistic about it, but it didn’t meet all my expectations.

Read more

My feelings about RuPy 2009

I just came back from the third edition of RuPy Conference, which take place in Poznań. As last year, it was very successful. There are my feelings about conference.

Read more

Cross-application partial w symfony

Ostatnio zetknąłem się z problemem wspólnych partiali dla wszystkich aplikacji w projekcie Symfony (dokładnie frontend i backend). Dokładniej, to te partiale były templatkami mailowymi, wysyłanymi zarówno przy zdarzeniach wygenerowanych w frontendzie jak i w panelu administracyjnym. Jako, że ponad wszystko cenię zasadę DRY (Don’t Repeat Yourself, czyli Nie Powtarzaj Się), chciałem, aby moje templatki były napisane raz, a używane z każdego miejsca w projekcie. Pewnym rozwiązaniem byłoby zrobienie symlinka: apps/frontend/modules/mails -> apps/backend/modules/mails i to działa, ale nie jest zbyt eleganckie. Z pomocą przyszła analiza kodu Symfony (dzięki Bogu, że jest Open Source:-)).

Read more
older
newer