Re: [PHP] Orphan functions?

2007-06-01 Thread Marc Weber
On Fri, Jun 01, 2007 at 03:01:48PM -0400, Al wrote:
 I gotcha now.  I misspoke about writing a tokenizer function, I understood 
 that it would be a script.
 
 That's for the suggestion.  Though, I was hoping to avoid reinventing 
 something that already exists.

There is another alternative. If you know C++ you can also use phc for
this task. (http://www.phpcompiler.org/)

Marc

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



Re: [PHP] scheduling a script to check a directory for files

2007-05-30 Thread Marc Weber
 I need to write a script to import '.csv' data files into MySQL.
 
 My question is how can I have a script execute and check a directory
 every 4 hours for any '.csv' files and if it finds any calls a function
 to import them?

On linux there is cron (you should find many example by googling)  on
windows there is the task scheduler...
And then finally you can use PHPs delay func and a loop ;)

The any part can be done by globbing, DirectoryIterator, shell scripts
.. 

Marc

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



[PHP] stack violation. after last line has been executed succesfully

2007-05-29 Thread Marc Weber
Hello. I've confirmed this problem on my gentoo linux box and using Xampp on 
windows..

= apache log =
  [Mon May 28 20:38:47 2007] [notice] child pid 16577 exit signal Aborted (6)
  *** glibc detected *** /usr/sbin/apache2: free(): invalid next size (fast): 
0x082b4d28 ***
  === Backtrace: =
  /lib/libc.so.6[0xb7b2b980]
  /lib/libc.so.6(__libc_free+0x89)[0xb7b2cfe9]
  /usr/lib/apache2/modules/libphp5.so(shutdown_memory_manager+0x48)[0xb77a0ef8]
  /usr/lib/apache2/modules/libphp5.so(php_request_shutdown+0x478)[0xb7776ab8]
  /usr/lib/apache2/modules/libphp5.so[0xb7839a18]
  /usr/sbin/apache2(ap_invoke_handler+0x182)[0x806b992]
  /usr/sbin/apache2(ap_process_request+0x15e)[0x806779e]
  /usr/sbin/apache2(apr_vformatter+0xab0)[0x80611f8]
  /usr/sbin/apache2(ap_process_connection+0x99)[0x80755b9]
  /usr/sbin/apache2[0x8068bc1]
  /usr/sbin/apache2[0x8068f56]
  /usr/sbin/apache2(ap_mpm_run+0x67e)[0x806964e]
  /usr/sbin/apache2(main+0x7df)[0x80701af]
  /lib/libc.so.6(__libc_start_main+0xd8)[0xb7add838]
  /usr/sbin/apache2(apr_bucket_mmap_make+0x69)[0x8060aa1]
  === Memory map: 
  08048000-080a r-xp  03:07 1310985/usr/sbin/apache2
  080a-080a3000 rw-p 00058000 03:07 1310985/usr/sbin/apache2
  080a3000-08349000 rw-p 080a3000 00:00 0  [heap]
  b6d0-b6d21000 rw-p b6d0 00:00 0 
=  ===

My code snippets

1) lib_marc\trunk\pages\Page.php|12 col 14|
protected $pageContentObjects = array();

2) lib_marc\trunk\pages\Page.php|19 col 13|
$this-pageContentObjects[] = $pageContent;

[ 3) lib_marc\trunk\pages\Page.php|55 col 73|
$p = A::merge_ignore_null_array( U::collect('urlParameters', 
$this-pageContentObjects) ); ]

4) lib_marc\trunk\pages\XHTMLPage.php|21 col 21|
foreach( $this-pageContentObjects as $pc){

1)  this is the declaration
2)  another object is added. when commenting this line out there is no problem 
at all.
[3)  doesn't matter]
4)  This is foreach loop is causing the trouble even if the loop has an empty 
body ( foreach (...)  {} )
But I can run vardump on it and it shows the item having been added
by 2)

So how can this foreach loop make PHP causing a stack violation?

Any ideas?

You can get the full source code here:
wget http://mawercer.de/marcweber/da.zip
(I'll remove the link again in some days)

I'm using PDO and mysql. The database configuration options can be found in 
config.php
Everything should be done automatically. (It does create a class location cache
to autoload them and it creates a file containing database metainformation to
execute type safe data queries.(MPDO.php) If you like it keep and use it and 
drop me a mail telling so ;)

Main entry point is index.php of course.
You need to click on link Kunden or use 
http://localhost/.../index.php?page=Kunden
to get this error.
I did use PHP 5.2.2 and mod_php (apache) I didn't try cgi.

Marc

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



[PHP] Re: Iterators

2007-02-13 Thread Marc Weber

What did I miss here?


In case somebody else wants to know.
I've found some examples in php sources ( ext/spl/tests/array_009.phpt )
This is the way to accomplish this:


$array = array(1, 2 = array(21, 22 = array(221, 222), 23 = array(231)),  
3);


$dir = new RecursiveIteratorIterator(new RecursiveArrayIterator($array),  
RecursiveIteratorIterator::LEAVES_ONLY);


foreach ($dir as $file) {
print $file\n;
}


Would be really nice to have some hints in documentation.

Marc

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



[PHP] static functions and array_map - why not allowed?

2007-02-13 Thread Marc Weber


Why can't I use static functions in array_map?

Example:

?php
class Dummy
{
  static public function T($a)
  {
echo T called with $a\n;
return $a+2;
  }
}

function t($a)
{
  echo t called with $a\n;
  return $a*2;
}

echo 'invoking Dummy::T works fine : ', Dummy::T(3),\n;
var_dump(array_map('t',array(1,2)));
var_dump(array_map('Dummy::T',array(1,2)));
?

Marc

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



[PHP] Where would you look for documentation about interface RecursiveIterator? RecursiveIteratorAggregate - suggestion

2007-02-13 Thread Marc Weber


http://de.php.net/~helly/php/ext/spl/interfaceRecursiveIterator.html

This piece of code


?php
$array = array(1, 2 = array(21, 22 = array(221, 222), 23 = array(231)),  
3);


$dir = new RecursiveIteratorIterator(new ArrayIterator($array));

foreach ($dir as $file) {
print $file\n;
}

?


results in


Fatal error: Uncaught exception 'InvalidArgumentException' with message  
'An instance of *RecursiveIterator* or IteratorAggregate creating it is  
required' in /tmp/t3.php:4

Stack trace:
/tmp/t3.php|4|  
RecursiveIteratorIterator-__construct(Object(ArrayIterator))

#1 {main}
  thrown in /tmp/t3.php on line 4


So this interface exists.

Why am I asking?

I've written a small html combinator library where each tag is represented  
as object.

Now I want to iterate over them using RecursiveIteratorIterator.

To be able to iterate over subElements I have to provide subIterator
 by exposing the interface RecursiveIterator, right?

I'd like to also implement IteratorAggregate instead
of Iterator because subtags are stored in arrays.
This doesn't work because RecursiveIterator does inherit from Iterator.
Thus I have to implement current, next, etc as well just beeing dummy
functions calling an internal iterator iterating over those elements?

Or is this much easier and there is a RecursiveIteratorAggregate interface?

Marc

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



Re: [PHP] Array to Object

2007-02-13 Thread Marc Weber
On Tue, Feb 13, 2007 at 12:02:10PM +0200, Eli wrote:
 Hi,
 
 Having this array:
 $arr = array(
   'my var'='My Value'
   );
 Notice the space in 'my var'.
 
 Converted to object:
 $obj = (object)$arr;
 
 How can I access $arr['my var'] in $obj ?

This works but there may be much better ways.

$n='my var';
echo ($obj-$n);

Marc

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



Re: [PHP] Where would you look for documentation about interface RecursiveIterator? RecursiveIteratorAggregate - suggestion

2007-02-13 Thread Marc Weber
On Tue, Feb 13, 2007 at 11:54:41AM +0100, Marc Weber wrote:
 

I've implemented a simple walk function which seems to be even easier
using php.
So consider this thread beeing no longer a problem :)

Marc

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



[PHP] segmentation fault - my fault?

2007-02-12 Thread Marc Weber
Does this script cause a segmentation fault running on your php
interpreter, too?

=  ===
?php

function fa()
{
  $res = array();
  foreach(func_get_args() as $a)
if (is_array($a)){
  foreach(fa($a) as $a2)
$res[]=$a2;
}else
  $res[]=$a;
  return $res;
}

var_dump(fa(array(1,2),array(array(3,4),array(5,6;
?
=  ===

My version:
[EMAIL PROTECTED] ~ $ php -v
PHP 5.1.6-pl6-gentoo (cli) (built: Feb 11 2007 02:37:11)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies

This function should take all elements in all arrays and flatten them down to 
one array.
Thus the result of the example above should be
array(1,2,..,6)

Marc

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



[PHP] Iterators

2007-02-12 Thread Marc Weber


?php

function A()
{
  return new RecursiveArrayIterator(array(func_get_args()));
}
$a=iterator_to_array(new RecursiveIteratorIterator( A (A(2) , A (3,4),  
A(5,6;

var_dump($a);

?

I'd expect this to output an array containing 2,3,4,5,6.
But the result is:

array(2) {
  [0]=
  int(5)
  [1]=
  int(6)
}

What did I miss here?

Marc

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



Re: [PHP] round to nearest 500?

2007-02-12 Thread Marc Weber

On Mon, 12 Feb 2007 18:02:41 +0100, [EMAIL PROTECTED] wrote:


Is there an easy way in php to round to the nearest 500?

Yeah
$rouned = round($val/500) * 500;

Marc

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



Re: [PHP] Iterators - seg faults again

2007-02-12 Thread Marc Weber
On Mon, 12 Feb 2007 20:33:08 +0100, Jochem Maas [EMAIL PROTECTED]  
wrote:




how should we know with out seeing the iterator_to_array() definition?

iterator_to_array() function is from php.
See http://de2.php.net/manual/en/function.iterator-to-array.php


Here is another testcase.
Why is this happening? Can you confirm this? What has to be done different?
If you don't get these results (sef faults (I still want to get 2,3,4,5,6)  
would you mind

telling me which version of php you are using?

The file is t.php and its appended at the bottom (cat t.php)

Thanks in advance Marc


[EMAIL PROTECTED] /tmp $ php t.php
 ==
 tescase is !!0!!
 ==
are the following two results the same?
1 :array(2) {
  [0]=
  int(5)
  [1]=
  int(6)
}
2 :current element in my_iterator_to_arrayArray
current element in my_iterator_to_array2
current element in my_iterator_to_array3
current element in my_iterator_to_array4
current element in my_iterator_to_array5
current element in my_iterator_to_array6
array(6) {
  [0]=
  array(3) {
[0]=
Segmentation fault


[EMAIL PROTECTED] /tmp $ php t.php
 ==
 tescase is !!1!!
 ==
are the following two results the same?
1 :array(2) {
  [0]=
  int(5)
  [1]=
  int(6)
}
2 :

foreach does print what I want (23456), why ?
2
3
4
5
6


running for each the second time results in segfault again. Why ?
Segmentation fault


[EMAIL PROTECTED] /tmp $ php -v
PHP 5.1.6-pl6-gentoo (cli) (built: Feb 11 2007 02:37:11)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies


[EMAIL PROTECTED] /tmp $ cat t.php
?php
$testcase = 1;
echo  ==\n;
echo  tescase is !!$testcase!!\n;
echo  ==\n;

function A()
{
  $a = func_get_args();
  return new RecursiveArrayIterator(array(func_get_args()));
}

function my_iterator_to_array($it)
{
	  echo $it instanceof IteratorAggregate; // doesn't output anything so  
result is false. So I don't have to try calling getIterator manually

  $res = array();
  while ($it-valid()){
echo current element in my_iterator_to_array, $it-current(),\n;
$res[] = $it-current();
$it-next();
  }
  return $res;
}

echo are the following two results the same?\n;
echo 1 :;
	var_dump(iterator_to_array(new RecursiveIteratorIterator( A (A(2) , A  
(3,4), A(5,6);

echo 2 :;
if ($testcase == 0)
	  var_dump(my_iterator_to_array(new RecursiveIteratorIterator( A (A(2) ,  
A (3,4), A(5,6);


$ri = new RecursiveIteratorIterator( A (A(2) , A (3,4), A(5,6)));

echo \n\nforeach does print what I want (23456), why ?\n;
foreach( $ri as $v) echo $v\n;
// why does the second foreach cause a segfault here?
	echo \n\nrunning for each the second time results in segfault again. Why  
?\n;

foreach( $ri as $v) echo $v\n;


?

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