[PHP] OOP problems

2011-12-15 Thread Dominik Halvoník
Hello,

I would like to ask you for help. This days I am trying to build one of my
applications. But I have problem which stopped me. I have folder whit php
files like connect.php, delete.php etc. These files contains classes named
the same as files. So in file connect.php is class Connect. These files are
placed in folder named mysql and this folder is inside folder named db. In
folder db is a php file named mysql.php, in this file I include classes
from folder mysql, after include I declare class MySQL and in it I have
method __construct(). In this method I create dynamic objects from included
classes. And this is the problem that I can not solve, I have more then one
of this files(mysql.php[whit class MySQL], oracle.php[whit class Oracle]
etc.) and I need to include them to file called db.php that is in the main
folder of my app. In db.php is an class called db, how can I add classes
MySQL, Oracle etc. to class db? I try to use abstract class whit __set and
__get methods but I also need to include class db to main class
application. I am really sorry for my English, so please be indulgent. So I
need to connect classes like this:

application-db-mysql-connect, but I can not use extends because in php
you can have only one parent class. The reason why I am trying to do
something like this is because I want to call methods like this:
$test = new application();
$test-db-connect();

If it is mysql or othet database I set in config.php file.

I need to achieve this schema( - is something like ../ it means that it is
one level up folder):

connec.php(class Connect MySql)-
select.php(class Select MySql) -
 - mysql.php(class MySQL include all classes, Connect...)-
 -
... -
- db.php(class db include all classes, MySQL, Oracle..)
connec.php(class Connect Oracle)-
select.php(class Select Oracle ) -
 - oracle .php(class Oracle include all classes, Connect...)-
 -
... -

download.php(class Download)-
unzip.php(class Unzip) -
 - files.php(class Files include all classes, Download...) -
file.php(class file include class Files)
 -
... -

hash.php(class Hash)-
capcha.php(class Capcha) -
 - secure.php(class Secure include all classes, Hash...) -
security.php(class security include class Secure)
 -
... -
ect. ect. ect. ect. ect. ect. ect. ect. ect. ect. ect. ect. ect. ect. ect.

And in the end, in the same folder as db.php and security.php I will have
file application.php which will contain class application and in its
__construct() method I will make link classes db, security, file ect. ect.
So I will just include file application.php make object from class
application and then just do $object-db-connect()(of course if it will by
MySql or other database will be stored in some config.php file).

Thanks,

Dominik


Re: [PHP] OOP problems

2011-12-15 Thread Alex Pojarsky
I'm not sure I've understood you correctly, but you may try something
like the following primitive autoloader (I didn't debug it, it's just
an example):

class Base
{
protected $_path = '';

public function construct($base_path)
{
$this-_path = $base_path;
}
public function __get($name)
{
$requested_path = $this-_path . DIRECTORY_SEPARATOR . $name;
if (is_dir($requested_path))
{
return new Base($requested_path);
}
else if (is_file($requested_path . '.php'))
{
include ($requested_path . '.php');
$classname = ucfirst($name);
return new $clasname();
}
}
}

// Assuming you have Mysql class in /home/user/project/classes/db/mysql.php
// you may try

$base = new Base(/home/user/project/classes/);
$base-db-mysql-someFunctionOfMysqlClass();

2011/12/15 Dominik Halvoník dominik.halvo...@gmail.com:
 Hello,

 I would like to ask you for help. This days I am trying to build one of my
 applications. But I have problem which stopped me. I have folder whit php
 files like connect.php, delete.php etc. These files contains classes named
 the same as files. So in file connect.php is class Connect. These files are
 placed in folder named mysql and this folder is inside folder named db. In
 folder db is a php file named mysql.php, in this file I include classes
 from folder mysql, after include I declare class MySQL and in it I have
 method __construct(). In this method I create dynamic objects from included
 classes. And this is the problem that I can not solve, I have more then one
 of this files(mysql.php[whit class MySQL], oracle.php[whit class Oracle]
 etc.) and I need to include them to file called db.php that is in the main
 folder of my app. In db.php is an class called db, how can I add classes
 MySQL, Oracle etc. to class db? I try to use abstract class whit __set and
 __get methods but I also need to include class db to main class
 application. I am really sorry for my English, so please be indulgent. So I
 need to connect classes like this:

 application-db-mysql-connect, but I can not use extends because in php
 you can have only one parent class. The reason why I am trying to do
 something like this is because I want to call methods like this:
 $test = new application();
 $test-db-connect();

 If it is mysql or othet database I set in config.php file.

 I need to achieve this schema( - is something like ../ it means that it is
 one level up folder):

 connec.php(class Connect MySql)-
 select.php(class Select MySql) -
  - mysql.php(class MySQL include all classes, Connect...)-
  -
 ... -
 - db.php(class db include all classes, MySQL, Oracle..)
 connec.php(class Connect Oracle)-
 select.php(class Select Oracle ) -
  - oracle .php(class Oracle include all classes, Connect...)-
  -
 ... -

 download.php(class Download)-
 unzip.php(class Unzip) -
  - files.php(class Files include all classes, Download...) -
 file.php(class file include class Files)
  -
 ... -

 hash.php(class Hash)-
 capcha.php(class Capcha) -
  - secure.php(class Secure include all classes, Hash...) -
 security.php(class security include class Secure)
  -
 ... -
 ect. ect. ect. ect. ect. ect. ect. ect. ect. ect. ect. ect. ect. ect. ect.

 And in the end, in the same folder as db.php and security.php I will have
 file application.php which will contain class application and in its
 __construct() method I will make link classes db, security, file ect. ect.
 So I will just include file application.php make object from class
 application and then just do $object-db-connect()(of course if it will by
 MySql or other database will be stored in some config.php file).

 Thanks,

 Dominik

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



Re: [PHP] OOP problems

2011-12-15 Thread Fatih P.


On 12/15/2011 01:05 PM, Alex Pojarsky wrote:

I'm not sure I've understood you correctly, but you may try something
like the following primitive autoloader (I didn't debug it, it's just
an example):

class Base
{
 protected $_path = '';

 public function construct($base_path)
 {
 $this-_path = $base_path;
 }
 public function __get($name)
 {
 $requested_path = $this-_path . DIRECTORY_SEPARATOR . $name;
 if (is_dir($requested_path))
 {
 return new Base($requested_path);
 }
 else if (is_file($requested_path . '.php'))
 {
 include ($requested_path . '.php');
 $classname = ucfirst($name);
 return new $clasname();
 }
 }
}

// Assuming you have Mysql class in /home/user/project/classes/db/mysql.php
// you may try

$base = new Base(/home/user/project/classes/);
$base-db-mysql-someFunctionOfMysqlClass();

2011/12/15 Dominik Halvoníkdominik.halvo...@gmail.com:

Hello,

I would like to ask you for help. This days I am trying to build one of my
applications. But I have problem which stopped me. I have folder whit php
files like connect.php, delete.php etc. These files contains classes named
the same as files. So in file connect.php is class Connect. These files are
placed in folder named mysql and this folder is inside folder named db. In
folder db is a php file named mysql.php, in this file I include classes
from folder mysql, after include I declare class MySQL and in it I have
method __construct(). In this method I create dynamic objects from included
classes. And this is the problem that I can not solve, I have more then one
of this files(mysql.php[whit class MySQL], oracle.php[whit class Oracle]
etc.) and I need to include them to file called db.php that is in the main
folder of my app. In db.php is an class called db, how can I add classes
MySQL, Oracle etc. to class db? I try to use abstract class whit __set and
__get methods but I also need to include class db to main class
application. I am really sorry for my English, so please be indulgent. So I
need to connect classes like this:

application-db-mysql-connect, but I can not use extends because in php
you can have only one parent class. The reason why I am trying to do
something like this is because I want to call methods like this:
$test = new application();
$test-db-connect();

If it is mysql or othet database I set in config.php file.

I need to achieve this schema( -  is something like ../ it means that it is
one level up folder):

connec.php(class Connect MySql)-
select.php(class Select MySql) -
 -  mysql.php(class MySQL include all classes, Connect...)-
 -
... -
-  db.php(class db include all classes, MySQL, Oracle..)
connec.php(class Connect Oracle)-
select.php(class Select Oracle ) -
 -  oracle .php(class Oracle include all classes, Connect...)-
 -
... -

download.php(class Download)-
unzip.php(class Unzip) -
 -  files.php(class Files include all classes, Download...) -
file.php(class file include class Files)
 -
... -

hash.php(class Hash)-
capcha.php(class Capcha) -
 -  secure.php(class Secure include all classes, Hash...) -
security.php(class security include class Secure)
 -
... -
ect. ect. ect. ect. ect. ect. ect. ect. ect. ect. ect. ect. ect. ect. ect.

And in the end, in the same folder as db.php and security.php I will have
file application.php which will contain class application and in its
__construct() method I will make link classes db, security, file ect. ect.
So I will just include file application.php make object from class
application and then just do $object-db-connect()(of course if it will by
MySql or other database will be stored in some config.php file).

Thanks,

Dominik

Why don't you modify include_path on initialization of 'Base' class?

would make things much simpler.

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



Re: [PHP] OOP problems

2011-12-11 Thread Dominik Halvoník
Hi guys,

I try to applied your solutions but I have problems whit it. I need to
achieve this schema( -  is something like ../ it means that it is one
level up folder):

connec.php(class Connect MySql)-
select.php(class Select MySql) -
 - mysql.php(class MySQL
include all classes, Connect...)-
 -
...  -

  -
db.php(class db include all classes, MySQL, Oracle..)
 connec.php(class Connect Oracle)-
select.php(class Select Oracle ) -
 -  oracle .php(class
Oracle include all classes, Connect...)-
 -
...  -

download.php(class Download)-
unzip.php(class Unzip) -
 - files.php(class Files
include all classes, Download...) - file.php(class file include class
Files)
 -
...  -

hash.php(class Hash)-
capcha.php(class Capcha) -
 - secure.php(class Secure
include all classes, Hash...) - security.php(class security include class
Secure)
 -
...  -
*ect. ect. ect.  ect. ect. ect. ect. ect. ect. ect. ect. ect. ect. ect. ect.
*

And in the end, in the same folder as db.php and security.php I will have
file application.php which will contain class application and in its
__construct() method I will make link classes db, security, file ect. ect.
So I will just include file application.php make object from class
application and then just do $object-db-connect()(of course if it will by
MySql or other database will be stored in some config.php file).

Thanks,

Dominik


[PHP] OOP problems

2011-12-08 Thread Dominik Halvoník
Hello,

I would like to ask you for help. This days I am trying to build one of my
applications. But I have problem which stopped me. I have folder whit php
files like connect.php, delete.php etc. These files contains classes named
the same as files. So in file connect.php is class Connect. These files are
placed in folder named mysql and this folder is inside folder named db. In
folder db is a php file named mysql.php, in this file I include classes
from folder mysql, after include I declare class MySQL and in it I have
method __construct(). In this method I create dynamic objects from included
classes. And this is the problem that I can not solve, I have more then one
of this files(mysql.php[whit class MySQL], oracle.php[whit class Oracle]
etc.) and I need to include them to file called db.php that is in the main
folder of my app. In db.php is an class called db, how can I add classes
MySQL, Oracle etc. to class db? I try to use abstract class whit __set and
__get methods but I also need to include class db to main class
application. I am really sorry for my English, so please be indulgent. So I
need to connect classes like this:

application-db-mysql-connect, but I can not use extends because in php
you can have only one parent class. The reason why I am trying to do
something like this is because I want to call methods like this:
$test = new application();
$test-db-connect();

If it is mysql or othet database I set in config.php file. Can you help my
please?

Sincerely,

Dominik Halvonik


Re: [PHP] OOP problems

2011-12-08 Thread Stuart Dallas
On 8 Dec 2011, at 17:14, Dominik Halvoník wrote:

 I would like to ask you for help. This days I am trying to build one of my
 applications. But I have problem which stopped me. I have folder whit php
 files like connect.php, delete.php etc. These files contains classes named
 the same as files. So in file connect.php is class Connect. These files are
 placed in folder named mysql and this folder is inside folder named db. In
 folder db is a php file named mysql.php, in this file I include classes
 from folder mysql, after include I declare class MySQL and in it I have
 method __construct(). In this method I create dynamic objects from included
 classes. And this is the problem that I can not solve, I have more then one
 of this files(mysql.php[whit class MySQL], oracle.php[whit class Oracle]
 etc.) and I need to include them to file called db.php that is in the main
 folder of my app. In db.php is an class called db, how can I add classes
 MySQL, Oracle etc. to class db? I try to use abstract class whit __set and
 __get methods but I also need to include class db to main class
 application. I am really sorry for my English, so please be indulgent. So I
 need to connect classes like this:
 
 application-db-mysql-connect, but I can not use extends because in php
 you can have only one parent class. The reason why I am trying to do
 something like this is because I want to call methods like this:
 $test = new application();
 $test-db-connect();
 
 If it is mysql or othet database I set in config.php file. Can you help my
 please?


You don't say what the db class (in db.php) itself does other than wrapping the 
database-specific classes, so I've assumed it doesn't do anything. If it does 
do more then simply have the mysql, oracle, etc classes extend db.

I've also assumed that the application doesn't need to support multiple 
database types simultaneously.

class application
{
  public $db = null;

  function __construct($db = 'mysql')
  {
require __DIR__.'/db/'.$db.'.php';
$this-db = new MySQL();
  }
}

$test = new application('mysql');
$test-db-connect();

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/

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



Re: [PHP] OOP problems

2011-12-08 Thread Mokaddim Akm
Sent from a handheld device

On 08-Dec-2011, at 11:14 PM, Dominik Halvoník
dominik.halvo...@gmail.com wrote:

 Hello,

 I would like to ask you for help. This days I am trying to build one of my
 applications. But I have problem which stopped me. I have folder whit php
 files like connect.php, delete.php etc. These files contains classes named
 the same as files. So in file connect.php is class Connect. These files are
 placed in folder named mysql and this folder is inside folder named db. In
 folder db is a php file named mysql.php, in this file I include classes
 from folder mysql, after include I declare class MySQL and in it I have
 method __construct(). In this method I create dynamic objects from included
 classes. And this is the problem that I can not solve, I have more then one
 of this files(mysql.php[whit class MySQL], oracle.php[whit class Oracle]
 etc.) and I need to include them to file called db.php that is in the main
 folder of my app. In db.php is an class called db, how can I add classes
 MySQL, Oracle etc. to class db? I try to use abstract class whit __set and
 __get methods but I also need to include class db to main class
 application. I am really sorry for my English, so please be indulgent. So I
 need to connect classes like this:


This is where common design patters comes handy.
Your problem can be solved by factory pattern.
Create a static method connect on db class. Then call it like
$db = DB::connect($db_type)

Here the db type variable contains MySQL or oracle. In connect static
method you implement the logic on how to connect that specific
database. In the connect method you can also take db credentials like
username and password.

Google php design pattern to know more.


 application-db-mysql-connect, but I can not use extends because in php
 you can have only one parent class. The reason why I am trying to do
 something like this is because I want to call methods like this:
 $test = new application();
 $test-db-connect();

 If it is mysql or othet database I set in config.php file. Can you help my
 please?

 Sincerely,

 Dominik Halvonik

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



[PHP] oop problems code

2003-09-18 Thread ORLANDO POZO
Hello, mailing list, I have problem with this oop code:

?

class Person {
  var $name, $address, $age;
  function Person($name, $address, $age) {
$this-name = $name;
$this-address = $address;
$this-age = $age;
  }
}
Class Employee extends Person {
  var $position, $salary;
  function Employee($name, $address, $age, $position, 
$salary) {
$this-Person($name, $address, $age);
$this-position = $position;
$this-salary = $salary;
  }
}

Class Displayer extends Employee {
 function DisplayEmployee() {
  echo Name:  . $this-name . br;
  echo Address:  . $this-address . br;
  echo Age:  . $this-age . br;
  echo Position:  . $this-position . br;
  echo Salary:  . $this-salary . br;
 }
}
$obj1 = new Employee(Orlando J Pozo P,Calle 75 AV 
9B-10,20,Computer Engineer,$2000);
$obj2 = new Displayer;
$obj2-DisplayEmployee();

?

--
the output of it is:
Warning: Missing argument 1 for employee() in 
C:\htdocs\ojpp\poo\3\practica\Copy of 18.php on line 16

Warning: Missing argument 2 for employee() in 
C:\htdocs\ojpp\poo\3\practica\Copy of 18.php on line 16

Warning: Missing argument 3 for employee() in 
C:\htdocs\ojpp\poo\3\practica\Copy of 18.php on line 16

Warning: Missing argument 4 for employee() in 
C:\htdocs\ojpp\poo\3\practica\Copy of 18.php on line 16

Warning: Missing argument 5 for employee() in 
C:\htdocs\ojpp\poo\3\practica\Copy of 18.php on line 16
Name: 
Address: 
Age: 
Position: 
Salary: 

--

  I don't know what happen in this code, because, the 
last inheritance (Displayer Class) that I made, it is 
inherited the properties and methods of the Employee 
Class, and as Employee Class is also inherited the 
functionality of the parent class, the Displayer Class 
would be inherit this functionality, too.

  thanks if any could help me, regards, bye.

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


Re: [PHP] oop problems code

2003-09-18 Thread Leif K-Brooks
ORLANDO POZO wrote:

Hello, mailing list, I have problem with this oop code:

[snip bad code]

-- 

the output of it is:
[snip output]

-- 

  I don't know what happen in this code, because, the last inheritance 
(Displayer Class) that I made, it is inherited the properties and 
methods of the Employee Class, and as Employee Class is also inherited 
the functionality of the parent class, the Displayer Class would be 
inherit this functionality, too.

  thanks if any could help me, regards, bye.

If a class doesn't define a constructor, the constructor of its parent 
is used; the inherited constructor of displayer wants 6 parameters. 
Also, your code wouldn't do anything useful, since you don't set the 
values of $obj2 (did you expect it to get values from $obj1?).

--
The above message is encrypted with double rot13 encoding.  Any unauthorized attempt 
to decrypt it will be prosecuted to the full extent of the law.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] OOP Problems

2001-07-14 Thread Andrew Kirilenko

Hello!

I have following problem:

?
$container = new ccontainer();
$container-init();
$container-test1-foo();
$container-test2-foo();
$container-test2-owner-test1-foo();
$container-test1-owner-test2-foo();

class ccontainer
{
function ccontainer()
{
}

function init()
{
$this-test1 = new ctest($this);
$this-test2 = new ctest($this);
}
}

class ctest
{
function ctest($owner)
{
$this-owner = $owner;
}

function foo()
{
echo test!br;
}
}
?

Output of this script is:
---
test!
test!
test!
Fatal error: Call to a member function on a non-object in c:\www\a.php on
line 8
---

How to solve this problem???

Best regards,
Andrew Kirilenko,
Senior Programmer / System Administrator,
Internet Service.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] OOP Problems

2001-07-14 Thread teo

Hi Andrew!
On Sat, 14 Jul 2001, Andrew Kirilenko wrote:

 Hello!
 
 I have following problem:
 
 ?
 $container = new ccontainer();
 $container-init();
 $container-test1-foo();
 $container-test2-foo();
 $container-test2-owner-test1-foo();
[*]
 $container-test1-owner-test2-foo();
 
 class ccontainer
 {
 function ccontainer()
 {
 }
 
 function init()
 {
 $this-test1 = new ctest($this);
 $this-test2 = new ctest($this);
 }
 }
 
 class ctest
 {
 function ctest($owner)
 {
 $this-owner = $owner;
 }
 
 function foo()
 {
 echo test!br;
 }
 }
 ?
 
 Output of this script is:
 ---
 test!
 test!
 test!
 Fatal error: Call to a member function on a non-object in c:\www\a.php on
 line 8
 ---
 
 How to solve this problem???
 
at the moment marked [*] you are using test1-owner
test1-owner  is ccontainer *before* init() had the chance to set test2 to it,
so the class has no such property test2.

try a print_r($container) right after $cointainer-init() to see what I mean.

actually, you will notice that test2-owner doesn't have test2 member too!
cause at the moment it was created, the ccontainer was incomplete 
(the expression $this-test2 = new ctest ($this) evaluates right-to-left)

a quick hack would be to have a circular reference, by saying:
$this-owner = $owner; // note the amp; :)

but the way you create the classes seems just trouble. what exactly are you
trying to achive?


-- teodor

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]