php-general Digest 31 Oct 2011 21:46:07 -0000 Issue 7547

Topics (messages 315562 through 315569):

Re: function.session-start in Webmaster Tools
        315562 by: Rick Dwyer

Re: Novice question
        315563 by: John Allsopp

Re: Array has `trailing comma`, why not the same for function parameter list?
        315564 by: Daniel Brown

Novice: PHP array by reference question (by C++ programmer)
        315565 by: Manish Gupta
        315566 by: Manish Gupta
        315567 by: Louis Huppenbauer

Dependency Injection containers
        315568 by: robert mena
        315569 by: jean-baptiste verrey

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


----------------------------------------------------------------------
--- Begin Message --- But those pages, when loaded, do not display any PHP errors. Only webmaster tools is showing the function.session-start in a link to that page. When I looked up hte meaning of session-start function, I found others who have indicated that white space in front of the session tag can cause this... so I eliminated it. Not sure if that will fix as the page has never displayed an error and Google takes forever to recrawl the whole site.


 --Rick


On Oct 31, 2011, at 5:44 AM, Stuart Dallas wrote:

On 30 Oct 2011, at 20:30, Rick Dwyer wrote:

Hello all.

Not sure just how much of this is PHP related, but hoping someone has come across this before.

I Google's webmaster tools for a site I work on, they list more than 100 crawl errors for pages with URL's as follows:

http://mydomain.com/My-Directory/function.session-start

Can anyone explain why webmaster tools is seeing pages with links ending in "function.session-start"? I read up on the error itself... sometimes caused by whitespace before the session_start tag... have fixed that. Any info is appreciated.


You have PHP errors somewhere on your site. The error messages contain links that could result in those URLs. Find out what pages are linking to those URLs and check them for errors.

-Stuart

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


--- End Message ---
--- Begin Message ---
> cURL is the best one in my experience, but you have to manage security
> yourself. Meaning: Remember to escape/encode data.
>
> http://php.net/manual/en/book.curl.php

Thanks everyone, appreciated, I'll investigate ..

Cheers
J

>> --
>> 01723 376477
>>
>> Cost-free marketing: http://www.flowmarketing.co.uk/
>>
>> Affordable marketing guidance for small businesses:
>> http://www.amilliontweaks.co.uk/
>>
>> Effective marketing services for SMEs: coming soon at
>> http://www.surgemarketing.co.uk
>>
>> Professional Internet marketing consultancy:
>> http://www.johnallsopp.co.uk
>>
>>
>> --
>> 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
>
>


-- 
01723 376477

Cost-free marketing: http://www.flowmarketing.co.uk/

Affordable marketing guidance for small businesses:
http://www.amilliontweaks.co.uk/

Effective marketing services for SMEs: coming soon at
http://www.surgemarketing.co.uk

Professional Internet marketing consultancy: http://www.johnallsopp.co.uk


--- End Message ---
--- Begin Message ---
On Sun, Oct 30, 2011 at 08:47, Nam Gi VU <nam.gi...@gmail.com> wrote:
> It is convenient to have a trailing comma when defining an array - so as
> easy to add/remove code to add/remove an entry to the array
>
> array(
>    'key00' => 'value00',
>    'key01' => 'value01',
>    'key02' => 'value02',
>    ...
> )
>
> I suggest to PHP Development team to make it available in the syntax to
> have a leading comma
> array(
>    ...
>    , 'key00' => 'value00'
>    , 'key01' => 'value01'
>    , 'key02' => 'value02'
> )
> in such way, we can thought of the leading commas as the list bulletings.
>
> And the same things would be lovely to be applied also to function
> parameter list. I don't see why not :)
>
> What do you thing about my suggestion? Hope to hear from you!

    For feature requests such as this, please discuss it on the
Internals list (CC'd on this email) and suggest it via the bug tracker
at https://bugs.php.net/ (with the bug type as a "Feature/Change
Request").

-- 
</Daniel P. Brown>
Network Infrastructure Manager
http://www.php.net/

--- End Message ---
--- Begin Message --- I have a class that takes as input, an array by reference and stores it in a member variable. A method in this class later modifies the member variable (which contains reference to the array). When I access the local variable that was passed by reference to the constructor of this class object, I see the local variable hasn't changed at all. I think code will describe what words may not have:

<?php

class foo
{
   public $_bar;
   public function  __construct(& $bar)
   {
       $this->_bar = $bar;
   }

   function do_your_thing()
   {
       $temp = array(
           'One' => 1,
           'Two' => 2
       );

       $this->_bar[] = $temp;

       echo('from Do_your_thing: ');
       print_r($this->_bar);   // ---------------- [1]
   }
}

$abc = array();
$var = new foo($abc);
$var->do_your_thing();

echo('from main [local variable]: ');
print_r($abc);   // ---------------- [2]

echo('from main: [object member variable] ');
print_r($var->_bar);    // ---------------- [3]
?>

I expected the output from [1], [2] and [3] to be the same. But instead I get the following:

from Do_your_thing: Array
(
   [0] => Array
       (
           [One] => 1
           [Two] => 2
       )

)
from main [local variable]: Array
(
)
from main: [object member variable] Array
(
   [0] => Array
       (
           [One] => 1
           [Two] => 2
       )

)

What am I missing? Please help, I'm new to PHP and this is really blocking me.

Thanks
M@nish
--- End Message ---
--- Begin Message ---
I have a class that takes as input, an array by reference and stores it in a
member variable. A method in this class later modifies the member variable
(which contains reference to the array). When I access the local variable
that was passed by reference to the constructor of this class object, I see
the local variable hasn't changed at all. I think code will describe what
words may not have:

<?php

class foo
{
   public $_bar;
   public function  __construct(& $bar)
   {
       $this->_bar = $bar;
   }

   function do_your_thing()
   {
       $temp = array(
           'One' => 1,
           'Two' => 2
       );

       $this->_bar[] = $temp;

       echo('from Do_your_thing: ');
       print_r($this->_bar);   // ---------------- [1]
   }
}

$abc = array();
$var = new foo($abc);
$var->do_your_thing();

echo('from main [local variable]: ');
print_r($abc);   // ---------------- [2]

echo('from main: [object member variable] ');
print_r($var->_bar);    // ---------------- [3]
?>

I expected the output from [1], [2] and [3] to be the same. But instead I
get the following:

from Do_your_thing: Array
(
   [0] => Array
       (
           [One] => 1
           [Two] => 2
       )

)
from main [local variable]: Array
(
)
from main: [object member variable] Array
(
   [0] => Array
       (
           [One] => 1
           [Two] => 2
       )

)

What am I missing? Please help, I'm new to PHP and this is really blocking
me.

Thanks
M@nish


--- End Message ---
--- Begin Message ---
---------- Forwarded message ----------
From: Louis Huppenbauer <louis.huppenba...@gmail.com>
Date: 2011/10/31
Subject: Re: [PHP] Novice: PHP array by reference question (by C++
programmer)
To: Manish Gupta <gman...@gmail.com>


You have to assign the value by reference too

public function  __construct(& $bar)
  {
      $this->_bar = &$bar;
  }


2011/10/31 Manish Gupta <gman...@gmail.com>

>  I have a class that takes as input, an array by reference and stores it
> in a
> member variable. A method in this class later modifies the member variable
> (which contains reference to the array). When I access the local variable
> that was passed by reference to the constructor of this class object, I see
> the local variable hasn't changed at all. I think code will describe what
> words may not have:
>
> <?php
>
> class foo
> {
>   public $_bar;
>   public function  __construct(& $bar)
>   {
>       $this->_bar = $bar;
>   }
>
>   function do_your_thing()
>   {
>       $temp = array(
>           'One' => 1,
>           'Two' => 2
>       );
>
>       $this->_bar[] = $temp;
>
>       echo('from Do_your_thing: ');
>       print_r($this->_bar);   // ---------------- [1]
>   }
> }
>
> $abc = array();
> $var = new foo($abc);
> $var->do_your_thing();
>
> echo('from main [local variable]: ');
> print_r($abc);   // ---------------- [2]
>
> echo('from main: [object member variable] ');
> print_r($var->_bar);    // ---------------- [3]
> ?>
>
> I expected the output from [1], [2] and [3] to be the same. But instead I
> get the following:
>
> from Do_your_thing: Array
> (
>   [0] => Array
>       (
>           [One] => 1
>           [Two] => 2
>       )
>
> )
> from main [local variable]: Array
> (
> )
> from main: [object member variable] Array
> (
>   [0] => Array
>       (
>           [One] => 1
>           [Two] => 2
>       )
>
> )
>
> What am I missing? Please help, I'm new to PHP and this is really blocking
> me.
>
> Thanks
> M@nish
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
Hi,

I am trying to avoid reinventing the wheel so I am looking for
dependency injection containers that work with PHP 5.2.  So Symphony2
and ZF2 DI are out of question.

I found this 
http://www.potstuck.com/2010/09/09/php-dependency-a-php-dependency-injection-framework/
 but I was wondering if anyone has a opinion about it or alternatives.

regards.

--- End Message ---
--- Begin Message ---
Hi,

you could simply write your own, you simply need a class or a function that
given an identifier such as "database.connector" would return you an
instance of it, and
and maybe handle singletons.
It just a question of taste of how you want it to be.

I have just posted a few days ago my implementation, it might interest you
(I think it should work with php 5.2)

<?php
class Dependency {
    protected $_singletonInstances = array();
    protected $_setInstances = array();
    protected $_configuration;

    protected static $_instance;

    public static function getInstance() {
        if (self::$_instance===null) {
            self::$_instance = new self();
        }
        return self::$_instance;
    }

    public function setConfiguration(array $configuration) {
        $this->_configuration = $configuration;
    }

    public function getConfiguration() {
        return $this->_configuration;
    }

    public function __isset($serviceName) {
        return isset($this->_serviceInstances[$serviceName]);
    }

    public function __call($serviceName, $args) {
        // singleton
        if (isset($this->_configuration[$serviceName]) &&
$this->_configuration[$serviceName]['singleton']) {
            if (!isset($this->_singletonInstances[$serviceName])) {
                $rc = new
ReflectionClass($this->_configuration[$serviceName]['class']);
                $this->_singletonInstances[$serviceName] = empty($args) ?
$rc->newInstance() : $rc->newInstanceArgs($args);
            }
            $ret = $this->_singletonInstances[$serviceName];
        } else {
            // normal
            if (isset($this->_setInstances[$serviceName])) {
                $ret = $this->_setInstances[$serviceName];
                unset($this->_setInstances[$serviceName]);
            } else {
                $rc = new
ReflectionClass($this->_configuration[$serviceName]['class']);
                $ret = $this->_singletonInstances[$serviceName] =
empty($args) ? $rc->newInstance() : $rc->newInstanceArgs($args);
            }
        }
        return $ret;
    }

    public function __get($serviceName) {
        return $this->__call($serviceName, array());
    }

    public function __set($serviceName, $instance) {
        if (!is_object($instance))
            throw new Exception('instance must be an object');
        $this->_setInstances[$serviceName] = $instance;
    }
}

$di=Dependency::getInstance();
$di->setConfiguration(array(
    'database.connector'=>array(
        'singleton'=>true,
        'class'=>'DatabaseConnector'
    ),
    'database'=>array(
        'singleton'=>true,
        'class'=>'Database'
    )
));

class DatabaseConnector{}
class Database{
    protected $_connector;
    public function __construct(){

$this->setConnector(Dependency::getInstance()->{'database.connector'});
    }

    public function setConnector($connector){
        $this->_connector=$connector;
    }
}
class Test{
    protected $_database;
    public function __construct(){
        $this->setDatabase(Dependency::getInstance()->database);
    }

    public function setDatabase($db){
        $this->_database=$db;
    }

    public function getDatabase(){
        return $this->_database;
    }
}

$test=new Test();
var_dump($test->getDatabase());


regards,

Jean-Baptiste Verrey



On 31 October 2011 21:32, robert mena <robert.m...@gmail.com> wrote:

> Hi,
>
> I am trying to avoid reinventing the wheel so I am looking for
> dependency injection containers that work with PHP 5.2.  So Symphony2
> and ZF2 DI are out of question.
>
> I found this
> http://www.potstuck.com/2010/09/09/php-dependency-a-php-dependency-injection-framework/
>  but I was wondering if anyone has a opinion about it or alternatives.
>
> regards.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---

Reply via email to