Hello Márcio,

stdClass is simply an empty class, without any properties or methods.

The object in the code sample is used to return multiple values at once. He 
could also have used an associative array to achieve that, but by choosing an 
object, he shows his affinity to the object oriented programming style.

The empty stdClass has the advantage of being a "blank" class. You can assign 
new properties or methods without minding about properties and methods that 
already exist in the class.
Besides that, it also doesn't use much memory. (Don't see that as performance 
boosting tip! There are much better ways to do that. Besides that, 
comprehensible design > performance.)

By the way, there are many reasons for creating objects inside of other 
objects. This should not be considered an exception. I don't know where this 
code belongs to, so I can't clear out if it is good or bad OOP style.

Just think about everything in classes and objects - even return values or 
other things, that you would normally consider as "volatile". (eg. a network 

Have a nice day,

Austrian Optic Technologies GmbH
Eisgrubengasse 2-6, A-2334 Vösendorf/Austria
Firmenbuch Nr.: FN 93629s
Firmenbuchgericht: Landesgericht Wien
UID-NR.: ATU 14976908
Disclaimer: Diese Nachricht ist ausschließlich für den bezeichneten Adressaten 
oder deren Vertreter bestimmt. Sollten sie nicht der vorgesehene Adressat 
dieser E-Mail sein, so bitten wir Sie, sich mit dem Absender der E-Mail in 
Verbindung zu setzen. Jede Form der unauthorisierten Nutzung, Veröffentlichung, 
Vervielfältigung oder Weitergabe dieser E-Mail ist nicht gestattet.
This message is exclusively intended for the designated recipient or his 
representatives. If you are not the designated recipient of this e-mail, we 
kindly ask you to notify the sender of this e-mail. Any form of unauthorized 
use, publication, duplication or dissemination of this e-mail is prohibited. 

Von: MEM [mailto:tal...@gmail.com] 
Gesendet: Donnerstag, 30. Juli 2009 12:21
An: php-general@lists.php.net
Betreff: [PHP] stdClass - A newbie question

Hello everybody, 

In this class sketch:


class Pagination {

        public static function Pagination ($total_records, $limit, $page)


          $total_pages = ceil($total_records / $limit);

        $page = max($page, 1);

        $page = min($page, $total_pages);

        $offset = ($page -1) * $limit;

        $pagi_obj= new stdClass;

        $pagi_obj->total_pages = $total_pages;

        $pagi_obj->offset = $offset;

        $pagi_obj->limit = $limit;


        return $pagi_obj;




Why do the author used a stdClass ?
What are the advantages of using a stdClass?

Since we are already inside a class, why do we need to create a new object
from another class, inside this one? 
Why do we keep the values passed as params on method Pagination inside this
stdClass object, and not inside Pagination own properties for example? 

Any help clarifying this, knowing that I'm a newbie,


PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to