Re: [PHP] Updating inherited attributes without __construct()

2008-06-06 Thread Tyson Vanover
Sorry, I probably should have included the add() 
function from the parent.  As well as all of the parent 
constructor.


Basically the object takes an array of key=>value pairs 
and parses them into a string for output.  When it 
takes in the array of pairs it needs to check the keys 
against a list of valid keys.  I have no preference on 
how to store the list of valid keys other than to add 
more a constructor doesn't need to be called.


class parent{
  $validkeys = 'name,size';
  $attributes = array();

  __construct($set){
foreach($set as $key=>$value){
  if(isValidKey($key)){
$this->attributes[$key] = $value;
  }
}
  }

  __toString(){
$output = "";
foreach($this->attributes as $key=>value){
  $output .= sprintf(TEMPLATE, $key, $value);
}
  }

  __set($key, $value){
if(isValidKey($key)){
  $this->attributes[$key] = $value;
}
  }

  isValidKey($key){
  ...Something goes here...
  }
}

class child extends parent{
...All this needs to do is tack on values 'color,shape' 
to parent's valid keys...

}

class grandchild extends child{
...All this needs to do is tack on values 
'cost,location' to child's valid keys...

}

Most sub classes won't need anything different from 
their parent but the expanded list of valid keys.


Nathan Nobbe wrote:

i dont quite understand this reasoning.. if you want to add some valid keys,
based upon the design of the parent, it seems to me the children do have a
need for an overridden constructor.  if you have accessor methods w/ a
consistent naming convention, you could omit the $validKeys array
altogether, and determine if a given field is valid based upon runtime
introspection.  something like this,

/// in the parent class
protected function isFieldValid($field) {
  if(method_exists($this, 'get' . ucfirst($field)))
return true;
  else
return false;
}

this will work in all the child classes as well, as long as you stick to a
consistent naming convention, and you can of course add a check for a set..
method as well if you like.  im not saying this technique is the holy grail
or anything, im merely offering it as an alternative to your current
solution.

-nathan

> On Thu, Jun 5, 2008 at 12:15 PM, Tyson Vanover 
<[EMAIL PROTECTED]> wrote:

>
>> I have a class that has a list of valid keys, and 
an array of values.  When
>> a value is added to the array it's key is first 
checked against the list of
>> valid keys (this is to prevent injection issues we 
have been having later on

>> in the project).
>>
>>  class parent{
>>private $validkeys = 'title,color,name';
>>private $values = array();
>>  }
>> That class is inherited by other classes that 
mostly just have an expanded
>> list of valid keys.  I would like to be able to 
update the valid key list
>> without having to craft a constructor for child 
objects.  I would rather not

>> give each child class the constructor,
>>
>>  __construct()
>>  {
>>$this->validkeys.= ',setting,...';
>>parent::__construct();
>>  }
>>
>> since most child classes have no need of a unique 
constructor.


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



[PHP] Updating inherited attributes without __construct()

2008-06-05 Thread Tyson Vanover
I have a class that has a list of valid keys, and an 
array of values.  When a value is added to the array 
it's key is first checked against the list of valid 
keys (this is to prevent injection issues we have been 
having later on in the project).


  class parent{
private $validkeys = 'title,color,name';
private $values = array();
  }
That class is inherited by other classes that mostly 
just have an expanded list of valid keys.  I would like 
to be able to update the valid key list without having 
to craft a constructor for child objects.  I would 
rather not give each child class the constructor,


  __construct()
  {
$this->validkeys.= ',setting,...';
parent::__construct();
  }

since most child classes have no need of a unique 
constructor.


I thought of defining a protected extended valid keys 
variable in the parent that the child could set that 
the parent constructor would combine with the valid keys.


class parent{
  private $validkeys = 'title,color,name';
  private $values = array();
  protected $extendedkeys;
  __construct(){
$this->validkeys .= $this->extendedkeys;
  }
}

But the children may become parents for further child 
classes.  And if the sub-child classes use the 
$extendedkeys variable it will overwrite the 
intermediate class's version.


Is there any way to tack on extra additional data by 
the child classes without creating a constructor.  I am 
not wedded to strings as a means, it just needs to be 
able to hold a string value.


Thanks

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



[PHP] Quickly verifying single word.

2008-06-04 Thread Tyson Vanover
I need a quick way to make sure that a string is a 
single word with no white spaces.  I would prefer that 
it is a command that could fit on a single line.  Or at 
least an if block.


I have a few thoughts on this but it involves things 
like explode(), stripslashes(), etc.


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



[PHP] Re: Still not getting Includes right.

2008-05-19 Thread Tyson Vanover

nevermind.  It is working now.  Thanks all!

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



[PHP] Re: Still not getting Includes right.

2008-05-19 Thread Tyson Vanover

Nevermind, working.

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



[PHP] Still not getting Includes right.

2008-05-19 Thread Tyson Vanover
So have developed some nice tools for generating forms, 
connecting to databases, things that I do repeatedly. 
When I run test pages that include these utility files 
in the same directory as the utility files it works 
fine.  The are included no problem.  As soon as I have 
scripts in other directories include these utility 
tools it breaks.


Here is my path structure
Page that uses the tools:
/srv/www/html/lib/index.html

Tools:
/srv/www/html/Tools/formtool/formtool.php
/srv/www/html/Tools/dbtool/dbtool.php
/srv/www/html/secdepot/libquery.inc

phpinfo() returns:
doc_root/srv/www/html   /srv/www/html
include_path.:/srv/www/html .:/srv/www/html

in the index.html I have tried:
ini_set( 'include_path', 
'/srv/www/html/Tools:/srv/www/html/secdepot:.');

require 'dbtools/dbtool.php';
require 'libquery.inc';
require 'formtool/formclasses.php';
errors:
 require(dbtools/dbtool.php) [function.require]: 
failed to open stream: No such file or directory 
/srv/www/html/lib/index.php, line 12
require() [function.require]: Failed opening required 
'dbtools/dbtool.php' 
(include_path='/srv/www/html/Tools:/srv/www/html/secdepot:.') 
/srv/www/html/lib/index.php, line 12


as well as:
require '/srv/www/html/Tools/dbtools/dbtool.php';
require '/srv/www/html/secdepot/libquery.inc';
require '/srv/www/html/Tools/formtool/formclasses.php';
error:
 require(/srv/www/html/Tools/dbtools/dbtool.php) 
[function.require]: failed to open stream: No such file 
or directory  /srv/www/html/lib/index.php, line 11
require() [function.require]: Failed opening required 
'/srv/www/html/Tools/dbtools/dbtool.php' 
(include_path='.:/srv/www/html') 
/srv/www/html/lib/index.php, line 11


as well as:
require 'dbtools/dbtool.php';
require 'libquery.inc';
require 'formtool/formclasses.php';
error:
 require(Tools/dbtools/dbtool.php) [function.require]: 
failed to open stream: No such file or directory 
/srv/www/html/lib/index.php, line 11
require() [function.require]: Failed opening required 
'Tools/dbtools/dbtool.php' 
(include_path='.:/srv/www/html') 
/srv/www/html/lib/index.php, line 11


as far as I can tell I am not chrooted:
?>ps aux | grep httpd
outputs:
root  1937  0.0  5.2  25600 13456 ?Ss 19:50 
  0:00 /usr/sbin/httpd
raa-web   1956  0.3  0.8   4636  2084 ?S 19:50 
  0:14 /usr/sbin/lighttpd -f /etc/raa/lighttpd.conf
apache1987  0.0  4.2  25736 10920 ?S 19:50 
  0:00 /usr/sbin/httpd
apache1990  0.0  4.2  25736 10892 ?S 19:50 
  0:00 /usr/sbin/httpd
apache1993  0.0  4.3  25736 11048 ?S 19:50 
  0:00 /usr/sbin/httpd
apache1995  0.0  4.2  25736 10908 ?S 19:50 
  0:00 /usr/sbin/httpd
apache2003  0.0  4.2  25736 10912 ?S 19:50 
  0:00 /usr/sbin/httpd
apache2008  0.0  4.2  25736 10908 ?S 19:50 
  0:00 /usr/sbin/httpd
apache2011  0.0  4.2  25736 10864 ?S 19:50 
  0:00 /usr/sbin/httpd
apache2014  0.0  4.2  25736 10900 ?S 19:50 
  0:00 /usr/sbin/httpd
root  2644  0.0  0.3   2908   788 tty1 R+ 20:57 
  0:00 grep httpd


Am I missing something blatently obvious?

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



Re: [PHP] Problems with includes

2008-05-16 Thread Tyson Vanover

Jim Lucas wrote:
 > Possibly that apache is chroot'ed.


I know you said LAMP.  But which OS/etc...

Sometimes you can see from the cli if httpd is rooted.

run 'ps aux | grep httpd' and see if httpd says anything about chroot



I don't see anything here

root  1937  0.0  5.2  25600 13456 ?Ss 
19:50   0:00 /usr/sbin/httpd
raa-web   1956  0.3  0.8   4636  2084 ?S 
19:50   0:14 /usr/sbin/lighttpd -f /etc/raa/lighttpd.conf
apache1987  0.0  4.2  25736 10920 ?S 
19:50   0:00 /usr/sbin/httpd
apache1990  0.0  4.2  25736 10892 ?S 
19:50   0:00 /usr/sbin/httpd
apache1993  0.0  4.3  25736 11048 ?S 
19:50   0:00 /usr/sbin/httpd
apache1995  0.0  4.2  25736 10908 ?S 
19:50   0:00 /usr/sbin/httpd
apache2003  0.0  4.2  25736 10912 ?S 
19:50   0:00 /usr/sbin/httpd
apache2008  0.0  4.2  25736 10908 ?S 
19:50   0:00 /usr/sbin/httpd
apache2011  0.0  4.2  25736 10864 ?S 
19:50   0:00 /usr/sbin/httpd
apache2014  0.0  4.2  25736 10900 ?S 
19:50   0:00 /usr/sbin/httpd
root  2644  0.0  0.3   2908   788 tty1 R+ 
20:57   0:00 grep httpd


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



Re: [PHP] Problems with includes

2008-05-16 Thread Tyson Vanover

Dan Joseph wrote:

Ok, I have changed my php.ini and restarted apache.  My include_path is set
to

include_path = ".:/srv/www/html"

but when I try from /srv/www/html/library/index.php:
require '/Tools/dbtools/dbtool.php';
or
require 'Tools/dbtools/dbtool.php';
or
require '../Tools/dbtools/dbtool.php';

I get the error:
require(/Tools/dbtools/dbtool.php) [function.require]: failed to open
stream: No such file or directory /srv/www/html/lib/index.php, line 10

require() [function.require]: Failed opening required
'/Tools/dbtools/dbtool.php' (include_path='.:/srv/www/html')
/srv/www/html/lib/index.php, line 10

any thoughts?  Am I missing something obvious?

>

It deosn't look like it updated your path.  Output a phpinfo() and make sure
you have the correct php.ini.  web servers tend to have more than one laying
around.


According to phpinfo() I am working with the correct 
php.ini (/etc/php5/php.ini).  And looking in the 
Configuration : PHP Core section "doc_root" is set to 
"/srv/www/html" and "include_path" is set to 
".:/srv/www/html".


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



Re: [PHP] Problems with includes

2008-05-16 Thread Tyson Vanover

Jim Lucas wrote:

Their are two ways that come to mind.

1. Like Dan suggested, use the full path.

2. (I prefer this way), change your include_path setting either in your 
php.ini file, virtual host, .htaccess or in your script to include the 
base path for your web site "/srv/www/html/" and then you can call them 
by simply removing the leading slash from your existing calls.

require 'Tools/tool1/tool1.php';
require 'Tools/tool2/tool2.php';



Ok, I have changed my php.ini and restarted apache.  My 
include_path is set to


include_path = ".:/srv/www/html"

but when I try from /srv/www/html/library/index.php:
require '/Tools/dbtools/dbtool.php';
or
require 'Tools/dbtools/dbtool.php';
or
require '../Tools/dbtools/dbtool.php';

I get the error:
require(/Tools/dbtools/dbtool.php) [function.require]: 
failed to open stream: No such file or directory 
/srv/www/html/lib/index.php, line 10


require() [function.require]: Failed opening required 
'/Tools/dbtools/dbtool.php' 
(include_path='.:/srv/www/html') 
/srv/www/html/lib/index.php, line 10


any thoughts?  Am I missing something obvious?

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



Re: [PHP] Problems with includes

2008-05-16 Thread Tyson Vanover

Jim Lucas wrote:


Their are two ways that come to mind.

1. Like Dan suggested, use the full path.

2. (I prefer this way), change your include_path setting either in your 
php.ini file, virtual host, .htaccess or in your script to include the 
base path for your web site "/srv/www/html/" and then you can call them 
by simply removing the leading slash from your existing calls.

require 'Tools/tool1/tool1.php';
require 'Tools/tool2/tool2.php';



So in say, php.ini, I set the include path to something 
like:


include_path = ".:/php/includes:/srv/www/html"

Will pointing it at "/srv/www/html" open up any 
security holes?


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



Re: [PHP] Problems with includes

2008-05-16 Thread Tyson Vanover

Dan Joseph wrote:


I'm pretty sure you're gonna need to include the entire path:

require( "/srv/www/html/Tools/tool2/tool2.php" );

for both of your tools.



So when php runs it's paths are drawn from the OS's 
structure and not apache's?  hun.  thanks!


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



[PHP] Problems with includes

2008-05-16 Thread Tyson Vanover
I am trying to keep my tools and pages segregated for a variety of 
reasons (organization, security, etc).  And I am having problems with my 
includes on my LAMP box.  My user facing tools are not including my 
utility classes and files.


The root directory of my web server (www.hostname.com/) is:
/srv/www/html/

My utility classes and files that need to be included by many of my user 
tools are in subdirectories of:

/srv/www/html/Tools
ie
/srv/www/html/Tools/tool1/tool1.php
/srv/www/html/Tools/tool2/tool2.php
included in these sub directories are tool testing pages 
(toolname-test.php) and other includes.  As long as the file that is 
including other files is in the same directory as the files it is 
including, it works just fine.


My user tools each have their own subdirectories off the webserver root
/srv/www/html/
ie
/srv/www/html/library/index.php


So I would think that to include my utility files into my user tools I 
would start the file with something like this:


require "/Tools/tool1/tool1.php";
require "/Tools/tool2/tool2.php";

But when I do I get:
require(/Tools/dbtools/dbtool.php) [function.require]: failed to open 
stream: No such file or directory  /srv/www/html/lib/index.php, line 16


require() [function.require]: Failed opening required 
'/Tools/dbtools/dbtool.php' (include_path='.:/usr/share/pear') 
/srv/www/html/lib/index.php, line 16


Am I missing something?

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



Re: [PHP] Mic check 1, 2, 3...

2008-05-14 Thread Tyson Vanover

tedd wrote:

At 1:50 PM -0700 5/14/08, Jim Lucas wrote:
Just wondering if the mailing list is working.  I have not received 
anything from this list today.


--
Jim Lucas


If you don't receive this, please let me know.

Cheers,

tedd



Wait... the recursive not testing of that statement just crashed my 
brain servers.


But I hope it is working for you Jim.

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



[PHP] Variable Scope from child to parent

2008-05-14 Thread Tyson Vanover
I am trying to get a child class to pass an array of valid keys to it's 
parent when the constructor is run, and the parent appends the data to 
one of it's array of valid keys.  Then it walks through an array pulling 
out values that have valid keys, and putting them in an array for 
processing later.  I have tried explicitly stating the variable scope.


abstract class parentclass
{
  protected $vkeys= array('title1','title2','title3');
  protected $a;

  function __construct($set = NULL, $special = NULL)
  {
self::$this->vkeys= array_merge(self::$this->vkeys, $special);
foreach($set as $key=>$value)
{
  if (in_array($key,self::$this->vkeys))
  {
$this->a[$key] = $value;
  }
}
print_r(self::$this->vkeys);  //output below
print_r(self::$this->a);  //output below
  }
}

class childclass extends parentclass
{
  protected $vkeys= array('titleA', 'titleB', 'TitleC');

  function __construct($set, $special = NULL)
  {
parent::__construct($set, self::$this->vkeys);
unset(self::$this->vkeys);
  }
}

Unfortunately it seems to duplicate the child's array instead of 
appending.  Explicitly stating scope does not seem to help.



print_r(self::$this->vkeys);
Array (
  [0] => titleA
  [1] => titleB
  [2] => titleB
  [3] => titleA
  [4] => titleB
  [5] => titleB
)

print_r(self::$this->a);
Array()

Any thoughts?

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



Re: [PHP] Tracking down the elusive "expecting T_PAAMAYIM_NEKUDOTAYIM"

2008-05-14 Thread Tyson Vanover

Daniel Brown wrote:

 $value) { // You just missed the $ before value.
?>

This seems to be the culprit.



Also, check this line:

titles)
?>

You're missing a ')' to close the if() statement.  It's not
causing this problem, but it will cause a problem afterward.



Thanks for catching that.

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



[PHP] Re: Two word array Value

2008-05-14 Thread Tyson Vanover

Mark Bomgardner wrote:


When I submit the form I am only getting the following having checked the
boxes for Mail Classroom and Break Out Classroom.  If I eliminate the spaces
between the words, I get everything, but when I put the spaces between the
words in the array, it cuts off the second word.  Not sure what is
happening?

 


Array ( [Main] => Main [Break] => Break [Submit] => Submit )




Look at the source of the page that this script generates.  Your input 
tags look like this


Classroom>Main Classroom


See the problem?  The html attribute values have spaces in them.  As far 
as your browser knows "Classroom" is supposed to be an attribute like 
type and value.  Since it doesn't understand it it drops it.


Here is some code, notice the \" surrounding the ".$key."

 "Main Classroom",
"Break Out Classroom" => "Break Out Classroom",
"Gym" => "Gym",
"Firearms Range" => "Firearms Range",
"EVOC Track" => "EVOC Track");
echo "";
echo "Equipment Needed";

foreach($vars as $key => $value){
  echo "value=\"".$value."\">".$value."";

}
echo "";
echo "";
?>

I also redid your layout.  You should be able to control the layout much 
better with some simple CSS.  Shoot me an e-mail if you wnat help with 
the CSS


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



[PHP] Tracking down the elusive "expecting T_PAAMAYIM_NEKUDOTAYIM"

2008-05-14 Thread Tyson Vanover

I have a class that is throwing the error:
syntax error, unexpected ')', expecting T_PAAMAYIM_NEKUDOTAYIM ...

It is appearing in the constructor of a parent class

abstract class parent
{
  protected $titles = array('title1','title2','title3');
  protected $a;

  function  __construct($set  =  NULL,  $special  =  NULL)
  {
self::$this->titles = array_merge(self::$this->titles, $special); 
//error


foreach($set  as  $key=>value)
{
  if  (array_key_exists($key,$this->titles)
  {
$this->a[$key]  =  $value;
  }
}
  }
}

class child extends parent
{
  protected $titles = array('titleA', 'titleB', 'titleC');

  function __construct($set, $special = NULL)
  {
self::$this->titles = array_merge(self::$this->titles, $special);
parent::__construct($set, self::$this->titles);
unset($this->titles);
  }
}

Basically parent is an extensible tool for holding data with titles that 
dictate behavior later in the script.  Eventually I will have a dozen or 
so different child classes each using an identical API.  But first I 
need this constructor to work.  The parent constructor just tacks the 
array of titles from the $special attributes onto the end of the $titles 
array.


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