php-general Digest 27 Dec 2009 02:57:40 -0000 Issue 6508

Topics (messages 300700 through 300704):

Re: uninstalling wamp
        300700 by: Carlos Medina

Accessing Objects - Object to Object Communication
        300701 by: Allen McCabe
        300702 by: Larry Garfield

Re: Multiple Inheritance Concern
        300703 by: Daniel Kolbo

Noob stuff - Zend/Opcode/Cache/Optimizer
        300704 by: Daniel Kolbo

Administrivia:

To subscribe to the digest, e-mail:
        [email protected]

To unsubscribe from the digest, e-mail:
        [email protected]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
Sudhakar schrieb:
hi

after installing wamp when i accessed phpmyadmin i got an error about root
having no password, i have tried various steps but could not get to use
phpmyadmin, so i uninstalled and reinstalled wamp, i deleted the old wamp
folder when i access phpmyadmin i get the same error message


i read that there are some files of wamp that need to be deleted from the
registery of windows, i am not very sure about regsitry as it is a bit risky
thing

can anyone advice how i can remove any unwanted wamp files and install wamp
so that i can access phpmyadmin page


thanks

Hi,
yes you can read first the Uninstall How To from Apachefriens

http://www.apachefriends.org/en/xampp-windows.html

Regards

Carlos

--- End Message ---
--- Begin Message ---
I have a Database class that I instantiate with credential information. The
connect method connects and creates a resource by the name $link_id. So if I
do this:

$db = new Database($server, $user, $password, $database);
$db->connect();

To get the resource (for use by mysql_insert_id() for example), I use
$db->link_id, so to get the last inserted record:
$id = mysql_insert_id($db->link_id);

Now for my question:

I have another class for creating pages (content). I have a method called
newPage() that accepts 4 arguments: title, content, role_id, display, and
description.

If I need to get the ID of this new page (which is inserted to a mysql table
with an id field with auto_increment), how would I access my database
object? Here is what I have, but first I should provide a brief explanation:
I am trying to pass the database object to any other object that needs to
access the database so that I am assured a connection exists before using
any query methods. So instead of  Database::query($sql), I have
$this->db->query($sql).

Here are some code snippets:

Content.class.php:
class Page {

    private $db;                // Contains reference to instance of the
Database class
    private $notify;            // Contains reference to instance of the
Notifier class
    private $URL;

    public function __construct($dbconnection, $root, $id = null)
    {
        $this->db = $dbconnection;
        $this->notify = Notifier::getInstance();
        $this->URL = $root . 'content/';

        if (isset($id)) {
            $result = $this->db->query('SELECT * FROM `content` WHERE
`page_id` = \''. $id .'\'');
            $data = $this->db->fetch_array($result);
        }
    }
}

header.php:
require_once('lib/class/Database.class.php');
$db = new Database($dbhost, $dbuser, $dbpass, $dbname);
$db->connect();
require_once('lib/class/Notifier.class.php');
$notify = Notifier::getInstance(); // self instantiates
require_once('lib/class/Content.class.php');
$page = new Page($db, ROOT);


Does this look right? I don't think I've ever seen two -> operators together
like this before...

I don't want to keep connecting to the database, and more importantly, my
Notifier class should only be a single instance, so I need to be able to
amend to a static array variable in that class from within other classes.

Thanks for any help you can provide, and happy holidays!

--- End Message ---
--- Begin Message ---
On Saturday 26 December 2009 3:38:44 pm Allen McCabe wrote:

> Here are some code snippets:
>
> Content.class.php:
> class Page {
>
>     private $db;                // Contains reference to instance of the
> Database class
>     private $notify;            // Contains reference to instance of the
> Notifier class
>     private $URL;
>
>     public function __construct($dbconnection, $root, $id = null)
>     {
>         $this->db = $dbconnection;
>         $this->notify = Notifier::getInstance();
>         $this->URL = $root . 'content/';
>
>         if (isset($id)) {
>             $result = $this->db->query('SELECT * FROM `content` WHERE
> `page_id` = \''. $id .'\'');
>             $data = $this->db->fetch_array($result);
>         }
>     }
> }
>
> header.php:
> require_once('lib/class/Database.class.php');
> $db = new Database($dbhost, $dbuser, $dbpass, $dbname);
> $db->connect();
> require_once('lib/class/Notifier.class.php');
> $notify = Notifier::getInstance(); // self instantiates
> require_once('lib/class/Content.class.php');
> $page = new Page($db, ROOT);
>
>
> Does this look right? I don't think I've ever seen two -> operators
> together like this before...
>
> I don't want to keep connecting to the database, and more importantly, my
> Notifier class should only be a single instance, so I need to be able to
> amend to a static array variable in that class from within other classes.
>
> Thanks for any help you can provide, and happy holidays!

Chaining multiple -> operators together like that is totally fine, and what 
you're doing here with the database is a good example of simple dependency 
injection.  In fact, you should do the same with the notifier class and pass it 
into the constructor of Page as well rather than making it a syntactic 
singleton.

For extra credit, wrap all of that into a factory function or factory object:

function create_page($root) {
  $db = create_your_db();
  $notifier = create_your_notifier();
  return new Page($db, $notifier, $root);
}
$new_page = create_page($my_root);

And the db and notifier routines can be as simple or complex as needed for your 
use case.  They could be singletons themselves, but don't have to be.  And in 
either case, Page() now doesn't know or care so you can change your mind 
without affecting Page.  Page is now loosely coupled, and all is right with the 
world.

-- 
Larry Garfield
[email protected]

--- End Message ---
--- Begin Message ---
Larry Garfield wrote:
> On Friday 25 December 2009 8:02:06 pm Daniel Kolbo wrote:
>> Hello PHPers,
>>
>> I've learned that php doesn't support multiple inheritance, b/c if you
>> need multiple inheritance usually it is a sign you've got a design
>> imperfection...or so they say.
>>
>> Well, I'm using a framework (Codeigniter), and i'm extending the core
>> libraries.  The trouble is, I want to also extend a second custom class,
>> and I don't want to change the core codeigniter class definitions as
>> this makes for awkward upgrades.
>>
>> I read about mixins - no thank you.  i do not want to even think about
>> mixins as it looks like it would be the source of all debug hell...
>>
>> What's a programmer to do?  Is the only option i am really left with to
>> duplicate the code in each class?
>>
>> Thanks,
>> dK
>> `
> 
> If the original author of one or both libraries did their job right, they'll 
> have provided an interface as well as the class that implements it.  Then you 
> can implement the interface and pass through to a new instance using 
> composition.
> 
> To wit:
> 
> interface AInterface {
>   public function doA();
> }
> 
> interface BInterface {
>   public function doB();
> }
> 
> class A implements AInterface {
>   public function doA() { ... }
> }
> 
> class B implements BInterface {
>   public function doB() { ... }
> }
> 
> class YourClass extends A implements BInterface {
> 
>   protected $b;
> 
>   public function __construct() {
>     $this->b = new B();
>   }
> 
>   public function doB() {
>     return $this->b->doB();
>   }
> }
> 
> (It would probably be a little more complicated in a real use case, but 
> hopefully that should get you the idea.)
> 
> Mind you, that presumes that the code you're dealing with provides interfaces 
> and when doing type checking checks against the interfaces rather than the 
> classes themselves.  If they don't, you should file a bug against that base 
> library as They're Doing It Wrong(tm).
> 

Yes, I understand.  Thanks for taking the time to write up the example.

Thanks,
dK
`

--- End Message ---
--- Begin Message ---
Hello,

I'm missing some unifying piece of the zend/php puzzle...

I understand the basics of zend engine opcode, caching the opcode,
optimizing the opcode, and caching the optimized opcode, etc...   The
part I'm struggling with is somewhere in the zend world.

Under a typical php install where does the zend engine live (like what
file)?

I am under the impression that I need to install the Zend Server
Community Edition (ZSCE) to get the zend optimizer+.  I thought PHP came
with the zend engine...why do i now have to download this ZSCE just to
add a component to the engine i already have?

1)  Is there a way to turn on zend optimizer+ component (like in php.ini
zend extension) without having to install ZSCE?

1.2) If i have to install the ZSCE stack, wouldn't this effectively be
adding another engine on my machine?

2) Does zend optimzer+ automatically cache the script's optimized opcode?

3) Is it possible to have APC cache the zend optimzer+ optimized opcode?

4) When APC automatically caches script's opcode is it doing this on
'per included file' basis or on the entire root script (like after the
root file has finished including all of its includes)?

5) Same as 4) but for zend optimizer+ instead of APC.

Thanks for helping me get a handle on this,
dK
`

--- End Message ---

Reply via email to