SplPriorityQueue::__construct

(PHP 5 >= 5.3.0, PHP 7)

SplPriorityQueue::__constructConstructs a new empty queue

说明

public SplPriorityQueue::__construct ( )

This constructs a new empty queue.

参数

此函数没有参数。

返回值

没有返回值。

User Contributed Notes

Jennifer 22-Mar-2011 12:19
I was trying to extend SplPriorityQueue like this:

<?php
class AdjustablePriorityQueue extends SplPriorityQueue {
    protected
$direction='desc';//queue is ordered highest to lowest priority, direction is changeable ONLY on __construct()

   
function __construct($direction='desc'){
       
parent::__construct(); //Fatal error:  Cannot call constructor
       
$this->direction=($direction=='asc') ? 'asc': 'desc';
    }

    function
compare($priority1,$priority2){
        if(
$this->direction=='asc') return parent::compare($priority2, $priority1);
        return
parent::compare($priority1,$priority2);
    }
}
?>

calling `parent::__construct()` gives a fatal error " Cannot call constructor".  If I leave out that call, everything works fine.  This suggests that SplPriorityQueue does not actually have a `__construct()` method.
PHP8中文手册 站长在线 整理 版权归PHP文档组所有