php-general Digest 4 Nov 2009 15:48:09 -0000 Issue 6426

2009-11-04 Thread php-general-digest-help

php-general Digest 4 Nov 2009 15:48:09 - Issue 6426

Topics (messages 299600 through 299618):

Re: Custom function for inserting values into MySQL
299600 by: Shawn McKenzie

Re: shell_exec fails to compile java class?
299601 by: Nathan Rixham
299602 by: Nathan Rixham

Re: What PHP version are you using?
299603 by: Nathan Rixham
299604 by: Nathan Rixham
299609 by: Ashley Sheridan

Re: Two Parser Passes
299605 by: Nathan Rixham
299606 by: Nathan Rixham

Re: Classes and Functions
299607 by: Nathan Rixham
299608 by: Nathan Rixham

Re: Apache file order
299610 by: Nathan Rixham

Re: PHP String convention
299611 by: Nathan Rixham
299614 by: Lars Torben Wilson
299616 by: Lars Torben Wilson

Re: It's not behaving. Error reporting, that is
299612 by: Philip Thompson
299613 by: Ashley Sheridan
299615 by: Nathan Rixham

Re: Using remote include config file and class in a local file
299617 by: Nathan Rixham

Re: Need unrounded precision
299618 by: Matthew McKay

Administrivia:

To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
php-gene...@lists.php.net


--
---BeginMessage---
In your example, I would name my form inputs similar to name
=data[user_id].

Then you just pass the $_POST['data'] array to your function.

-Shawn

Allen McCabe wrote:
 You raise some good points. I always name my input fields after the
 entity names ( eg. input type=hidden name =user_id value= ?php
 echo $resultRow['user_id'] ?  ).

 I suppose I am still in the phase of learning efficiency, and perhaps
 trying to 'get out it' by writing functions that I can just call and
 pass parameters instead of fully learning the core concepts.

 I just think functions are so damn cool :)


 I'll echo what the others have said about the parameters.  For me
 personally, if I am passing more than three parameters (sometimes even
 three) I rethink my function.  I'm not sure what you envision
 using this
 function for, but the approach I use for forms and databases is always
 arrays.  I get an array from my forms, I insert that array into the
 database, and of course I fetch arrays out of the database.  These are
 all indexed the same with the index as the field name of the table so
 it's easy.


 --
 Thanks!
 -Shawn
 http://www.spidean.com



---End Message---
---BeginMessage---

דניאל דנון wrote:

Hello!

I need to use shell_exec (or any other similar function) in order to compile
a java class-file.

I have all the needed components installed on my computer (Windows XP with
Java SDK) - I can use java c:\path in order to compile using
Start-Run.

When I try to do the same with shell_exec or `` it returns null and it
doesn't compiles. Even when there are errors - it doesn't show them at all.

I've tried to use instead of java c:\path... the full java command line
compiler path but it didn't work either.


When I try functions such as echo test it works.


Clearly I'm missing here something - problem is... what?



create an ant builder or .bat and call that instead; most likely because 
the environment isn't set up correctly when executing via php; thus when 
using ant or bat you can set everything up correctly as needed.


always use PHP on linux but permissions and the scope / permissions of 
the account php runs under may come in to play?


nathan
---End Message---
---BeginMessage---

דניאל דנון wrote:

Hello!

I need to use shell_exec (or any other similar function) in order to compile
a java class-file.

I have all the needed components installed on my computer (Windows XP with
Java SDK) - I can use java c:\path in order to compile using
Start-Run.

When I try to do the same with shell_exec or `` it returns null and it
doesn't compiles. Even when there are errors - it doesn't show them at all.

I've tried to use instead of java c:\path... the full java command line
compiler path but it didn't work either.


When I try functions such as echo test it works.


Clearly I'm missing here something - problem is... what?



create an ant builder or .bat and call that instead; most likely because 
the environment isn't set up correctly when executing via php; thus when 
using ant or bat you can set everything up correctly as needed.


always use PHP on linux but permissions and the scope / permissions of 
the account php runs under may come in to play?


nathan
---End Message---
---BeginMessage---

Israel Ekpo wrote:

Hi Guys,

I just want to conduct a quick survey to find out what version of PHP people
are using in their production environments.

I have a PHP extension for Solr that I have set the minimum required 

Re: [PHP] Custom function for inserting values into MySQL

2009-11-04 Thread Shawn McKenzie
In your example, I would name my form inputs similar to name
=data[user_id].

Then you just pass the $_POST['data'] array to your function.

-Shawn

Allen McCabe wrote:
 You raise some good points. I always name my input fields after the
 entity names ( eg. input type=hidden name =user_id value= ?php
 echo $resultRow['user_id'] ?  ).

 I suppose I am still in the phase of learning efficiency, and perhaps
 trying to 'get out it' by writing functions that I can just call and
 pass parameters instead of fully learning the core concepts.

 I just think functions are so damn cool :)


 I'll echo what the others have said about the parameters.  For me
 personally, if I am passing more than three parameters (sometimes even
 three) I rethink my function.  I'm not sure what you envision
 using this
 function for, but the approach I use for forms and databases is always
 arrays.  I get an array from my forms, I insert that array into the
 database, and of course I fetch arrays out of the database.  These are
 all indexed the same with the index as the field name of the table so
 it's easy.


 --
 Thanks!
 -Shawn
 http://www.spidean.com




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



[PHP] Re: shell_exec fails to compile java class?

2009-11-04 Thread Nathan Rixham

דניאל דנון wrote:

Hello!

I need to use shell_exec (or any other similar function) in order to compile
a java class-file.

I have all the needed components installed on my computer (Windows XP with
Java SDK) - I can use java c:\path in order to compile using
Start-Run.

When I try to do the same with shell_exec or `` it returns null and it
doesn't compiles. Even when there are errors - it doesn't show them at all.

I've tried to use instead of java c:\path... the full java command line
compiler path but it didn't work either.


When I try functions such as echo test it works.


Clearly I'm missing here something - problem is... what?



create an ant builder or .bat and call that instead; most likely because 
the environment isn't set up correctly when executing via php; thus when 
using ant or bat you can set everything up correctly as needed.


always use PHP on linux but permissions and the scope / permissions of 
the account php runs under may come in to play?


nathan

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



[PHP] Re: What PHP version are you using?

2009-11-04 Thread Nathan Rixham

Israel Ekpo wrote:

Hi Guys,

I just want to conduct a quick survey to find out what version of PHP people
are using in their production environments.

I have a PHP extension for Solr that I have set the minimum required version
as 5.2.11.

http://pecl.php.net/package/solr/

However, most of the PHP users that want to use it are unable to do so
because the PHP version in the PROD environments is below 5.2.11

They are also nervous about upgrading to newer versions as it will require
some regression testing.

In my production environment I am using 5.3.0 and most of the people that I
have contacted seems to be running 5.2.10

When I released the extension, I did all my regression tests against PHP
5.2.11 and now I am considering doing regression tests against 5.2.4
(released 30 August 2007)  and newer versions so that I can set the minimum
required version to 5.2.4 in order to accommodate more people.

I cannot go below 5.2.0 though but I am thinking about starting at 5.2.4 and
newer.

I would really appreciate some feedback as it will be useful in helping me
determine which PHP version numbers to do my regression tests against.

Thanks.



PHP 5.2.4-2 on most production boxes
mixed 5.1.6, 5.2 and 5.3's in dev environments

+ interesting release; wish I'd known spent part of the first week in 
october doing a SOLR integration in PHP *sigh* - on to virtuoso now


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



Re: [PHP] Two Parser Passes

2009-11-04 Thread Nathan Rixham

Daniel Kolbo wrote:

Steve wrote:

Daniel Kolbo wrote:

Hello,

Is it possible to get a list (array) of classes not found in a script
before the fatal error exits the parser.  I realize that PHP parses the
script twice.  It would be nice at the end of the first parsing pass to
check to see which classes haven't been defined (yet), so that I could
define them before the second pass.  This way I could load only those
classes a script needs.

Thanks in advance,
dK
`
  

It sounds like you are looking for autoload:
http://www.php.net/manual/language.oop5.autoload.php



Mr. Steve that's pretty cool.  Thanks.

Is there a similar type function for autoloading undefined functions?

Thanks,
dK
`


not afaik, but you should be able to hack it by catching errors, 
checking for undefined functions then loading your.lib.php file


imho it'd make more sense to wrap misc functions in a class or two as 
static methods though then you can take advantage of the autoloading.


also if you can use spl autoloading and registration so it plays nice 
with other libs.


regards

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



[PHP] Re: Classes and Functions

2009-11-04 Thread Nathan Rixham

Daniel Kolbo wrote:

Hello,

Is there a way to see what objects and functions a script
loaded/required/used?

I could recursively loop through the globals, but if objects were unset,
then i may miss some.

I could make a 'tracking' object and every time i load/include a file
(which contains a class def or a function def) to add that file to the
tracking object...but it would be nice if i didn't have to modify my
existing code to see which objects and functions a script actually used,
or at least, requested and loaded into memory.

Thanks in advance,
Daniel Kolbo
`



if it's for debugging, get a good debugger so you can inspect at break 
points; for use during runtime and something scripted you can call the 
relevant get_defined/declared functions before before your app does it's 
loading, then the same later on and compare to get a definitive list.


also worth asking if you're refering to objects (as in instances) or 
classes.


Object = instance of a Class [ $object = new Class() ]

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



Re: [PHP] Re: What PHP version are you using?

2009-11-04 Thread Ashley Sheridan
On Wed, 2009-11-04 at 14:37 +, Nathan Rixham wrote:

 Israel Ekpo wrote:
  Hi Guys,
  
  I just want to conduct a quick survey to find out what version of PHP people
  are using in their production environments.
  
  I have a PHP extension for Solr that I have set the minimum required version
  as 5.2.11.
  
  http://pecl.php.net/package/solr/
  
  However, most of the PHP users that want to use it are unable to do so
  because the PHP version in the PROD environments is below 5.2.11
  
  They are also nervous about upgrading to newer versions as it will require
  some regression testing.
  
  In my production environment I am using 5.3.0 and most of the people that I
  have contacted seems to be running 5.2.10
  
  When I released the extension, I did all my regression tests against PHP
  5.2.11 and now I am considering doing regression tests against 5.2.4
  (released 30 August 2007)  and newer versions so that I can set the minimum
  required version to 5.2.4 in order to accommodate more people.
  
  I cannot go below 5.2.0 though but I am thinking about starting at 5.2.4 and
  newer.
  
  I would really appreciate some feedback as it will be useful in helping me
  determine which PHP version numbers to do my regression tests against.
  
  Thanks.
  
 
 PHP 5.2.4-2 on most production boxes
 mixed 5.1.6, 5.2 and 5.3's in dev environments
 
 + interesting release; wish I'd known spent part of the first week in 
 october doing a SOLR integration in PHP *sigh* - on to virtuoso now
 
 


5.2.9 on my home laptop and main box (used for devel)
4.4.7 on my own site (stupid hosting company are useless!)
and a mix of 5.x's on the sites I develop

Thanks,
Ash
http://www.ashleysheridan.co.uk




[PHP] Re: Apache file order

2009-11-04 Thread Nathan Rixham

Skip Evans wrote:

Hey all,

I modified an Apache config file to list the HTML file first, after the 
PHP file, it still pulls up the PHP file first.


Is there another setting in Apache I should be looking for?

I need it to check for the HTML file first.

Thanks,
Skip

IfModule dir_module
DirectoryIndex index.html index.php
/IfModule




yup it may be in the .htaccess as well :)

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



[PHP] Re: PHP String convention

2009-11-04 Thread Nathan Rixham

Nick Cooper wrote:

Hi,

I was just wondering what the difference/advantage of these two
methods of writing a string are:

1) $string = foo{$bar};

2) $string = 'foo'.$bar;


1) breaks PHPUnit when used in classes (need to bug report that)
2) [concatenation] is faster (but you wouldn't notice)

comes down to personal preference and what looks best in your (teams) 
IDE I guess; legibility (and possibly portability) is probably the 
primary concern.



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



Re: [PHP] It's not behaving. Error reporting, that is

2009-11-04 Thread Philip Thompson

On Nov 3, 2009, at 11:24 AM, Kim Madsen wrote:


Hi Philip

Try to post a link to a page, that prints phpinfo()

--  
Kind regards

Kim Emax

Philip Thompson wrote on 2009-11-03 17:11:

Hi all.
This seems like a trivial issue to fix, but I'm having issues. I'm  
running a script via command line and it's throwing out PHP  
notices. Well, I want to suppress those notices. At the top of my  
script I have the line...

?php
error_reporting (E_ERROR);
?
...thinking that this would get rid of the notices. However, it did  
not. They still appear. I even attempted using ini_set(), but to no  
avail. I then set error_reporting in php.ini - this made no  
difference. (I shouldn't have to restart apache when running via  
command line, but for giggles, I did.) I then changed  
display_errors to Off. You guessed it - no change! This immediately  
brought up the question... Well, what php.ini is this script  
using? Here's my results...

[pthomp...@s-irv-pthompson scripts]$ php --ini
Configuration File (php.ini) Path: /etc
Loaded Configuration File: /etc/php.ini
Scan for additional .ini files in: /etc/php.d
...
Yup, according to PHP I'm using the correct ini. Now I'm at a loss.  
Can anyone shed some light on this big brain fart I'm having?  
Thanks in advance.

~Philip



--
Kind regards
Kim Emax - masterminds.dk


That's all good and dandy. But this is a cli application. And besides,  
the computer is not accessible via the Internet.


Thanks,
~Philip

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



Re: [PHP] It's not behaving. Error reporting, that is

2009-11-04 Thread Ashley Sheridan
On Wed, 2009-11-04 at 08:52 -0600, Philip Thompson wrote:

 On Nov 3, 2009, at 11:24 AM, Kim Madsen wrote:
 
  Hi Philip
 
  Try to post a link to a page, that prints phpinfo()
 
  --  
  Kind regards
  Kim Emax
 
  Philip Thompson wrote on 2009-11-03 17:11:
  Hi all.
  This seems like a trivial issue to fix, but I'm having issues. I'm  
  running a script via command line and it's throwing out PHP  
  notices. Well, I want to suppress those notices. At the top of my  
  script I have the line...
  ?php
  error_reporting (E_ERROR);
  ?
  ...thinking that this would get rid of the notices. However, it did  
  not. They still appear. I even attempted using ini_set(), but to no  
  avail. I then set error_reporting in php.ini - this made no  
  difference. (I shouldn't have to restart apache when running via  
  command line, but for giggles, I did.) I then changed  
  display_errors to Off. You guessed it - no change! This immediately  
  brought up the question... Well, what php.ini is this script  
  using? Here's my results...
  [pthomp...@s-irv-pthompson scripts]$ php --ini
  Configuration File (php.ini) Path: /etc
  Loaded Configuration File: /etc/php.ini
  Scan for additional .ini files in: /etc/php.d
  ...
  Yup, according to PHP I'm using the correct ini. Now I'm at a loss.  
  Can anyone shed some light on this big brain fart I'm having?  
  Thanks in advance.
  ~Philip
 
 
  -- 
  Kind regards
  Kim Emax - masterminds.dk
 
 That's all good and dandy. But this is a cli application. And besides,  
 the computer is not accessible via the Internet.
 
 Thanks,
 ~Philip
 


You can call a phpinfo() script from the CLI, but I don't think that's
your problem here. Have you tried setting any other php.ini variables at
all and had any success with that?

Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] PHP String convention

2009-11-04 Thread Lars Torben Wilson
2009/10/28 Warren Vail war...@vailtech.net:
 The curly braces look like something from the smarty template engine.

 Warren Vail

Odd. I always thought the curly braces in the Smarty engine looked
like something from PHP. :)


Torben

 -Original Message-
 From: Kim Madsen [mailto:php@emax.dk]
 Sent: Wednesday, October 28, 2009 10:18 AM
 To: Nick Cooper
 Cc: Jim Lucas; php-general@lists.php.net
 Subject: Re: [PHP] PHP String convention

 Hi Nick

 Nick Cooper wrote on 2009-10-28 17:29:

 Thank you for the quick replies. I thought method 2 must be faster
 because it doesn't have to search for variables in the string.

 So what is the advantages then of method 1 over 3, do the curly braces
 mean anything?

 1) $string = foo{$bar};

 2) $string = 'foo'.$bar;

 3) $string = foo$bar;

 I must admit reading method 1 is easier, but writing method 2 is
 quicker, is that the only purpose the curly braces serve?

 Yes, you're right about that. 10 years ago I went to a seminar were
 Rasmus Lerforf was speaking and asked him exactly that question. The
 single qoutes are preferred and are way faster because it doesn´t have
 to parse the string, only the glued variables.

 Also we discussed that if you´re doing a bunch of HTML code it's
 considerably faster to do:

 tr
   td?= $data ?/td
 /tr

 Than
 print 
 \n\ttr
   \n\t\ttd$data/td
 \n\t/tr;

 or
 print '
 tr
   td'.$data.'/td
 /tr';

 I remember benchmark testing it afterwards back then and there was
 clearly a difference.

 --
 Kind regards
 Kim Emax - masterminds.dk

 --
 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 General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] It's not behaving. Error reporting, that is

2009-11-04 Thread Nathan Rixham

Ashley Sheridan wrote:

On Wed, 2009-11-04 at 08:52 -0600, Philip Thompson wrote:


On Nov 3, 2009, at 11:24 AM, Kim Madsen wrote:


Hi Philip

Try to post a link to a page, that prints phpinfo()

--  
Kind regards

Kim Emax

Philip Thompson wrote on 2009-11-03 17:11:

Hi all.
This seems like a trivial issue to fix, but I'm having issues. I'm  
running a script via command line and it's throwing out PHP  
notices. Well, I want to suppress those notices. At the top of my  
script I have the line...

?php
error_reporting (E_ERROR);
?
...thinking that this would get rid of the notices. However, it did  
not. They still appear. I even attempted using ini_set(), but to no  
avail. I then set error_reporting in php.ini - this made no  
difference. (I shouldn't have to restart apache when running via  
command line, but for giggles, I did.) I then changed  
display_errors to Off. You guessed it - no change! This immediately  
brought up the question... Well, what php.ini is this script  
using? Here's my results...

[pthomp...@s-irv-pthompson scripts]$ php --ini
Configuration File (php.ini) Path: /etc
Loaded Configuration File: /etc/php.ini
Scan for additional .ini files in: /etc/php.d
...
Yup, according to PHP I'm using the correct ini. Now I'm at a loss.  
Can anyone shed some light on this big brain fart I'm having?  
Thanks in advance.

~Philip


--
Kind regards
Kim Emax - masterminds.dk
That's all good and dandy. But this is a cli application. And besides,  
the computer is not accessible via the Internet.


Thanks,
~Philip




You can call a phpinfo() script from the CLI, but I don't think that's
your problem here. Have you tried setting any other php.ini variables at
all and had any success with that?

Thanks,
Ash
http://www.ashleysheridan.co.uk





use -n to specify no ini file
-c /path/to/php.ini to specify and ini file
-d error_reporting=E_ALL to force the directive

and to check you can use
php -i | grep error_reporting


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



Re: [PHP] Re: PHP String convention

2009-11-04 Thread Lars Torben Wilson
2009/11/4 Nathan Rixham nrix...@gmail.com:
 Nick Cooper wrote:

 Hi,

 I was just wondering what the difference/advantage of these two
 methods of writing a string are:

 1) $string = foo{$bar};

 2) $string = 'foo'.$bar;

 1) breaks PHPUnit when used in classes (need to bug report that)
 2) [concatenation] is faster (but you wouldn't notice)

 comes down to personal preference and what looks best in your (teams) IDE I
 guess; legibility (and possibly portability) is probably the primary
 concern.

I would tend to agree here; the concat is faster but you may well only
notice in very tight loops. The curly brace syntax can increase code
readability, depending on the complexity of the expression. I  use
them both depending on the situation.

Remember the rules of optimization:

1) Don't.
2) (Advanced users only): Optimize later.

Write code so that it's readable, and then once it's working, identify
the bottlenecks and optimize where needed. If you understand code
analysis and big-O etc then you will start to automatically write
mostly-optimized code anyway and in general, I doubt that you'll often
identify the use of double quotes as a bottleneck--it almost always
turns out that other operations and code structures are far more
expensive and impact code speed much more.

That said, you don't really lose anything by using concatenation from
the start, except perhaps some legibility, so as Nathan said it often
really just comes down to personal preference and perhaps the house
coding conventions.


Regards,

Torben

 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] Re: Using remote include config file and class in a local file

2009-11-04 Thread Nathan Rixham

Shawn McKenzie wrote:

Anton Heuschen wrote:

Question is wrt to including a config file on an external server in a
local include

Lets say that on 127.0.0.1 I have test.php with

include http://200.200.1.1/Folder/Config.php

$obj = new RemoteClass()

do stuff


and on server 200.200.1.1 I have my Config.php file which is contains
the class RemoteClass() { echo test }



If I try to test it locally it says it cannot find RemoteClass ...


How can I include/require a config (or any other php classes file) on
my local running php script ?


As others have said, you are receiving the output of the config.php
after it has been parsed by PHP on the remote server.  You could try
naming it config.cfg, config.conf, config.ini, config.inc, etc...



multiple choice
- why not use PHAR
- on remote server enable .phps (php source)
- remove SetHandler application/x-httpd-php in you apache conf (if on 
apache, and obviously realise this won't let any php scripts run through 
http)

- mount the remote file system locally

and.. why? normal approach would be to expose the remote functionality 
needed as a web service and call it via SOAP/RPC/REST etc


however.. always fancied the idea of a central server for php libs that 
can be included at runtime (with some local cache'ing and version 
checking) - would make most sense if we all used a single version of the 
same libs  only one copy etc etc


regards

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



Re: [PHP] Need unrounded precision

2009-11-04 Thread Matthew McKay

Kim Madsen wrote:

Hello

Andre Dubuc wrote on 2010-01-02 02:20:

Hi,

I need to extract the first digit after the decimal point from a 
number such as 28.56018, which should be '5'.


Since no one came up with the simple solution:

$num = 28.56018;
ereg(^[0-9]+\.([0-9]){1}, trim($num), $regs);
if($regs[1])
  $digit = $regs[1];
else
  print no digit found;


My submission for a simple solution. I wish I had xslt2 =(
xsl:template name=firstDigit
   xsl:param name=number/
   xsl:value-of 
select=number(substring(substring-after(number(translate(normalize-space($number),translate(normalize-space($number),'.0123456789',''),'')),'.'),1,1))/

/xsl:template


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



Re: [PHP] Custom function for inserting values into MySQL

2009-11-04 Thread Nathan Rixham

Shawn McKenzie wrote:

Allen McCabe wrote:


Do you see any major hangups or screwups on first glance? And is my fear of
trying this out on my database unfounded? Does this even seem that useful?



in all honesty.. loads of screwups - don't try it out on your database  
ultimately if it isn't re-usable then it isn't useful (and it's isn't 
re-usable unless every single table you have is the same.. which they 
aren't)


to be a bit more constructive though.. this is a road most developers 
have been down, and well known solutions already exist.


You've got two choices..

1] continue down this route and learn as you go (but for god sake get a 
test database) - recommended if you really want to learn not just PHP 
but programming in general; once you understand it all you can go 
looking at design patterns, common solutions and how other people do it 
and have enough knowledge to make informed decisions.


2] just use what's made and don't think too much about it, you'll be 
productive and can throw in support/help requests whenever it goes 
wrong, works for some people.. to do this get a decent framework and 
read it's manual (or use pdo, or an ORM for PHP or something)


all depends on what you want, how much time you have, and where you want 
to end up.


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



Re: [PHP] Need unrounded precision

2009-11-04 Thread Nathan Rixham

Matthew McKay wrote:

Kim Madsen wrote:

Hello

Andre Dubuc wrote on 2010-01-02 02:20:

Hi,

I need to extract the first digit after the decimal point from a 
number such as 28.56018, which should be '5'.


Since no one came up with the simple solution:

$num = 28.56018;
ereg(^[0-9]+\.([0-9]){1}, trim($num), $regs);
if($regs[1])
  $digit = $regs[1];
else
  print no digit found;


My submission for a simple solution. I wish I had xslt2 =(
xsl:template name=firstDigit
   xsl:param name=number/
   xsl:value-of 
select=number(substring(substring-after(number(translate(normalize-space($number),translate(normalize-space($number),'.0123456789',''),'')),'.'),1,1))/ 


/xsl:template



nice to see a bit of xslt w/ functions :) just for the hell of it here's 
one off the top of my head


$num = 28.56018;
substr((int)($num*10) , -1); #5

and one without any functions..

(int)(($num-(int)$num)*10); #5




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



[PHP] Ottawa, Canada - PHP Developers

2009-11-04 Thread Robert Cummings

Hi All,

Any Ottawa based PHP developers out there that freelance / contract? 
Nothing to offer right now but we are creating a list of potential 
contacts related to open source within a Canadian Federal Government 
context... especially as relates to open-source and PHP. While 
telecommute would be a possibility, site/intranet access is often a 
requirement and thus limits the radius of applicability.


Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

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



[PHP] OO method inside a variable

2009-11-04 Thread simone.nanni

Hi everybody,
i'm trying to apply a method to an object getting its name from a  
variable, that i obtain parsing an XML file.


For example:

$object = new Class;
$method = row(); #I'm getting this from the XML parser
$object-$method; #I've an error here...

Obviously the method inside the class exists.
How can i do it?
Thanks a lot in advance.

Simone Nanni


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



Re: [PHP] OO method inside a variable

2009-11-04 Thread Eddie Drapkin
On Wed, Nov 4, 2009 at 4:36 PM,  simone.na...@ptvonline.it wrote:
 Hi everybody,
 i'm trying to apply a method to an object getting its name from a variable,
 that i obtain parsing an XML file.

 For example:

 $object = new Class;
 $method = row(); #I'm getting this from the XML parser
 $object-$method; #I've an error here...

 Obviously the method inside the class exists.
 How can i do it?
 Thanks a lot in advance.

 Simone Nanni


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



Use call_user_func() and call_user_func_array() with the callback format:

array($instance, 'method'); for instance methods or
array('class_name', 'method'); for static methods

so you'd want:

$obj = new Class();
$method = row;
call_user_func(array($obj, $method));

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



Re: [PHP] OO method inside a variable

2009-11-04 Thread Robert Cummings

simone.na...@ptvonline.it wrote:

Hi everybody,
i'm trying to apply a method to an object getting its name from a  
variable, that i obtain parsing an XML file.


For example:

$object = new Class;
$method = row(); #I'm getting this from the XML parser
$object-$method; #I've an error here...

Obviously the method inside the class exists.
How can i do it?
Thanks a lot in advance.


Your problem is the inclusion of parameters in the $method. You can do 
the following:


?php

$object = new Class;
$method = 'row';
$ret = $object-$method();

?

Or if you insist on embedded parameters (but this is a security risk):

?php

$object = new Class;
$method = 'row()';
$ret = eval( return \$object-$method; );

?

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

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



RE: [PHP] Custom function for inserting values into MySQL

2009-11-04 Thread Daevid Vincent
 -Original Message-
 From: Shawn McKenzie [mailto:nos...@mckenzies.net] 
 Sent: Wednesday, November 04, 2009 6:20 AM
 To: Allen McCabe; PHP General
 Subject: Re: [PHP] Custom function for inserting values into MySQL
 
 In your example, I would name my form inputs similar to name
 =data[user_id].
 
 Then you just pass the $_POST['data'] array to your function.
 
 -Shawn
 
 Allen McCabe wrote:
  You raise some good points. I always name my input fields after the
  entity names ( eg. input type=hidden name =user_id value= ?php
  echo $resultRow['user_id'] ?  ).
 
  I suppose I am still in the phase of learning efficiency, 
 and perhaps
  trying to 'get out it' by writing functions that I can just call and
  pass parameters instead of fully learning the core concepts.
 
  I just think functions are so damn cool :)
 
 
  I'll echo what the others have said about the 
 parameters.  For me
  personally, if I am passing more than three parameters 
 (sometimes even
  three) I rethink my function.  I'm not sure what you envision
  using this
  function for, but the approach I use for forms and 
 databases is always
  arrays.  I get an array from my forms, I insert that 
 array into the
  database, and of course I fetch arrays out of the 
 database.  These are
  all indexed the same with the index as the field name 
 of the table so
  it's easy.
 
 
  --
  Thanks!
  -Shawn
  http://www.spidean.com
 
 
 

There are pro's and cons to this type of thing. In general that is how I do
it too, but you have to be aware of security and organization. It's not
always smart to expose your DB field names directly so you might want to
obscure them for some critical values. If your passing from one controlled
function/method to another then this isnt an issue so much. 

I also follow the ruby/rails ideal where tables are plural names (users)
and classes are singular names (user.class.php). Tables always have fields
for 'id','created_on','timestamp','enabled'. Except in 'glue table' cases
(1:n or n:m). Classes extend a base class which handles a lot of the minutea
including the magic __get() and __set() routines as well as knowing what
table they should be through introspection (ie. Their own file name). 

No need to name your fields as arrays. $_POST is already an array. You've
just added more complexity/dimensions. When you submit your form just pass
$_POST to your function instead. In the function, is where you should do any
normalizing, scrubbing and unsetting (as per good MVC ideology)...

In your page form:

if ($_POST['submit'] == 'Update')
{
   $result = process_data($_POST);
}

Then in some include file somewhere (here is a simplified example of
course):

function process_data($data)
{
   //perhaps you don't care about the submit button
   unset($data['submit']); 

   //maybe you don't want everyone to know your DB schema 
   //so you re-map from form element names to DB fields...
   $data['user_id'] = $data['uid']; 
   unset($data['uid']);

   //strip white space off
   foreach ($data as $k = $v) $data[$k] = trim($v); 

   //do validity checking of each important data item
   if (intval($data['user_id'])  1) return false;

   //any other pre-processing

   //do interesting stuff here with scrubbed $data array now
   sql_query('UPDATE mytable SET .. WHERE user_id = '.$data['user_id'].'
LIMIT 1');

   //of course, I would use a routine that builds the update / insert
statements from
   //the array key/value pairs -- see previous attached example
base.class.php in this thread.
}

http://daevid.com


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