Re: [PHP] Re: Help with OOPHP (SOLVED)

2007-11-01 Thread Andrew Peterson

I've figured it out :)

Thanks for the help, I just need to walk away for a minute and come  
back to it.


all I need to do is this:



myClass.php
--
?PHP
require mySecondClass.php;

class myClass
{
/*
		Now I can create/edit/maninpulate/etc new and old instances of  
mySecondClass

*/
}

?



mySecondClass.php
---
?PHP

mySecondClass
{
//constuct, functions, etc
}


?








On Nov 1, 2007, at 7:35 AM, Sebastian Hopfe wrote:


Dear Andrew,

I think normaly it isn't possible to use another class in a class,  
without using extends. But you should use your array as a  
container. After you use as a container, you can make new instance  
into a array field.


Now you can use the content of the container to administrate the  
instances of the complete class. I just changed some things at your  
example. Please have a look and ask if you have any questions.


?php

 class fruitBasket ext
 {
   private $fruits = array();  //this is a class Container

   public function addFruit($newFruit)
   {
 $this-fruits[] = new fruit($newFruit);
   }

   public function makeAllApples()
   {
 foreach($this-fruits AS $fruit)
 {
   $fruit-changeName(apple);
 }
   }

   public function showAllFruits()
   {
 foreach($this-fruits AS $fruit)
 {
   echo $fruit-showFruit().br;
 }
   }
 }

 class fruit
 {
   private $name;

   public function __construct($name)
   {
 $this-name = $name;
   }

   public function changeName($newName)
   {
 $this-name = $newName;
   }

   public function showFruit()
   {
 return $this-name;
   }
 }

 $Cls = new fruitBasket();

 $Cls-addFruit(test1);
 $Cls-addFruit(test2);
 $Cls-addFruit(test3);
 $Cls-addFruit(test4);
 $Cls-addFruit(test5);
 $Cls-addFruit(test6);

 $Cls-makeAllApples();

 $Cls-showAllFruits();

?

Andrew Peterson [EMAIL PROTECTED] schrieb im Newsbeitrag  
news:[EMAIL PROTECTED]

I'm hoping you guys can help me out.

I'm not sure if you can do this, but i'm trying to create a class   
that is build of another class.  I also want to be able to do   
functions on the class1 from within class2.



example:

class fruitBasket{

private $fuit = array();  //this is a class

public function addFruit($newFruit)
{
$this-fruitBasket[] = $newFruit();
}

public makeAllApples()
{
foreach($this-fruit AS $value)
{ $value-changeName(apple);
} }

}



class fruit{

private $name;

public __construct($name)
{
$this-name = $name;
}

public changeName($newName)
{
$this-name = $newName;
}
}


--
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



[PHP] Help with OOPHP

2007-10-31 Thread Andrew Peterson

I'm hoping you guys can help me out.

I'm not sure if you can do this, but i'm trying to create a class  
that is build of another class.  I also want to be able to do  
functions on the class1 from within class2.



example:

class fruitBasket{

private $fuit = array();  //this is a class

public function addFruit($newFruit)
{
$this-fruitBasket[] = $newFruit();
}

public makeAllApples()
{
foreach($this-fruit AS $value)
{   
$value-changeName(apple);
}   
}

}



class fruit{

private $name;

public __construct($name)
{
$this-name = $name;
}

public changeName($newName)
{
$this-name = $newName;
}
}

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



[PHP] Security Question

2007-10-17 Thread Andrew Peterson
Does anyone know a good way to protect a directory that a php script NEEDS
to write too?

What I'm doing now:

1. create a directory manually myDir
2. chmod 777 myDir
3. password protect the directory with htaccess

Is this the best way, or is there something better?

Also, is there a way to mkdir or fopen a file dynamically, without
pre-creating a directory with 777 permissions?

Thanks for the help,
Andrew