首页 \ 问答 \ 从__constructor返回false(Return false from __constructor)

从__constructor返回false(Return false from __constructor)

你能否从构造函数返回false?

<?php


class ftp_stfp{

    //private vars of the class
    private $host;
    private $username;
    private $password;
    private $connection_type;
    private $connection = false;


    function __contruct( $host, $username, $password, $connection_type ){

        //setting the classes vars
        $this->host         = $host;
        $this->username     = $username;
        $this->password     = $password;
        $this->connection_type = $connection_type;

        //now set the connection into this classes connection
        $this->connection = $this->connect();

        //check the connection was set else return false
        if($this->connection === false){
            return false;   
        } 
    } ... etc etc the rest of the class

致电课程:

$ftp_sftp = new ftp_sftp( $host, $uname, $pword, $connection_type );

这实际上是正确的,也就是说$ ftp_sftp var是false还是保持类取决于__construct方法的结果,还是这是完全错误的逻辑?


Can you return false from the contructor?

<?php


class ftp_stfp{

    //private vars of the class
    private $host;
    private $username;
    private $password;
    private $connection_type;
    private $connection = false;


    function __contruct( $host, $username, $password, $connection_type ){

        //setting the classes vars
        $this->host         = $host;
        $this->username     = $username;
        $this->password     = $password;
        $this->connection_type = $connection_type;

        //now set the connection into this classes connection
        $this->connection = $this->connect();

        //check the connection was set else return false
        if($this->connection === false){
            return false;   
        } 
    } ... etc etc the rest of the class

Call the class:

$ftp_sftp = new ftp_sftp( $host, $uname, $pword, $connection_type );

Is this actually correct, ie would the $ftp_sftp var either be false or hold the class depending on outcome of the __construct method, or is this completely wrong logic?


原文:https://stackoverflow.com/questions/14295761
更新时间:2023-05-16 16:05

最满意答案

当你在同一个文件系统上创建一个文件时,系统只需要改变目录条目以反映你的重命名。 文件中的数据甚至没有被读取。

(相同的文件系统意味着:相同的目录或相同的目录树/同一个驱动器,前提是源目录和目标目录不会遍历导致另一个文件系统的符号链接!)

当你跨越文件系统创建一个文件时,它与cp + rm具有相同的效果:没有速度增益(除了你只运行一个命令并保证一致性的事实:你不必检查cp是否成功执行rm)

(旧版本的mv拒绝在文件系统中移动目录,因为它们只做了重命名)

小心,它不等同。 默认情况下, cp覆盖目标,而mv将无法将文件/目录重命名为现有文件/目录。


When you mv a file on the same filesystem, the system just has to change directory entries to reflect your renaming. Data in the file is not even read.

(same filesystem means: same directory or same directory tree/same drive, provided that source and destination directories do not traverse symlinks leading to another filesystem of course!)

When you mv a file across file systems, it has the same effect as cp + rm: no speed gain (apart from the fact that you only run one command, and consistency is guaranteed: you don't have to check if cp succeeded to perform the rm)

(older versions of mv refused to move directories across filesystems, because they only did the renaming)

Be careful, it is not equivalent. cp overwrites destination by default, whereas mv will fail renaming a file/dir into an existing file/dir.

相关问答

更多
  • 而不是使用clock()来测量时间,你应该事件: 使用事件你会有这样的事情: cudaEvent_t start, stop; // variables that holds 2 events float time; // Variable that will hold the time cudaEventCreate(&start); // creating the event 1 cudaEventCreate(&stop); // crea ...
  • System.Buffer.BlockCopy更接近C的memcpy但仍有开销。 对于小案例,您自己的方法通常会更快,而对于大案例,BlockCopy会更快。 复制引用比复制int更慢,因为在分配引用时,.NET在大多数情况下必须做一些额外的工作 - 这个额外的工作与垃圾收集有关。 有关此事实的演示,请查看下面的代码,其中包含用于复制每个字符串元素的本机代码与复制每个int元素(本机代码在注释中)。 请注意,它实际上进行函数调用以将字符串引用分配给src [i],而int是内联完成的: static ...
  • 在我回答你的问题之前,有一件事似乎是错误的:C ++ 11中的价值并不总是意味着复制。 如果一个rvalue被传递,那将被移动 (提供一个可行的移动构造函数存在),而不是被复制。 而std::string确实有一个移动构造函数。 与C ++ 03不同的是,在C ++ 11中,通常按惯例来取参数,原因如下。 另请参阅StackOverflow上的此问答,以获取有关如何接受参数的更为一般的指导方针。 为什么我们不采取rvalue参考str ? 因为这样就不可能传递左值,例如: std::string s = " ...
  • 是的,一个班级可以复制但不可移动是合法的: class MyClass { public: /* Copyable... */ MyClass(const MyClass&); MyClass& operator= (const MyClass&); /* ... but not movable. */ MyClass(MyClass&&) = delete; MyClass& operator= (MyClass&&) = delete; }; 然而,我 ...
  • TL; DR - 这是缓存问题 在任务管理器中运行基准测试打开的“ 性能”选项卡时,您会看到差异来自哪里。 在Files.copy测试期间,您可能会看到高磁盘写入速度。 但是当transferTo测试运行时,磁盘将几乎空闲! 这意味着没有数据实际写入设备 - 复制在内存中执行。 这显然要快得多。 Java Files.copy方法是使用CopyFileEx WinAPI函数实现的。 没有明确规定CopyFileEx如何在内部工作,但是观察到它会做一些实际的磁盘I / O. 依次transferTo执行一系列 ...
  • 您可以在返回NSDragOperation时检查是否按下了ALT(Option)键。 例: if context == NSDraggingContext.OutsideApplication { return .None } else { // get the current global event object // and compare its modifier flags with ours if let event = NSApplication.shared ...
  • 找到了我自己的问题的解决方案! 1. hadoop按目录获取所有日期并在本地保存。 例如 hadoop fs -get / warehouse / elephant / f_transactions_report / date = 2012-12 *〜/ elephant 2. Hadoop将所有本地保存的目录放回到新目的地。 例如 hadoop fs -put~ / elephant / warehouse / elephant / f_transactional_events / 目录结构将保持不变。 ...
  • 当你在同一个文件系统上创建一个文件时,系统只需要改变目录条目以反映你的重命名。 文件中的数据甚至没有被读取。 (相同的文件系统意味着:相同的目录或相同的目录树/同一个驱动器,前提是源目录和目标目录不会遍历导致另一个文件系统的符号链接!) 当你跨越文件系统创建一个文件时,它与cp + rm具有相同的效果:没有速度增益(除了你只运行一个命令并保证一致性的事实:你不必检查cp是否成功执行rm) (旧版本的mv拒绝在文件系统中移动目录,因为它们只做了重命名) 小心,它不等同。 默认情况下, cp覆盖目标,而mv将无 ...
  • 如果src和dst在不同的文件系统上os.rename(src, dst)则无法保证os.rename(src, dst)正常工作。 如果dst存在,它在Windows上不起作用。 就像文档说的那样 There is no guarantee that os.rename(src, dst) works if src and dst are on different filesystems. And it does not work on Windows if dst exists. Just as the ...
  • 如名称所示,复制构造函数/赋值运算符应始终COPY而不移动其成员,其中复制通常表示深层复制。 记住:默认情况下,c ++中的所有对象都应该具有值语义,即它们应该像int 。 此外,帖子中的术语表明您将独特对象(单例)与unique_ptr指向的对象混淆。 大多数不可复制的对象都是处理程序(如unique_ptr处理堆上的对象),在这种情况下,您可以复制它们处理的任何内容。 如果那是不可能的,那么最有可能的是,实现对象的复制构造函数是没有意义的。 如果您的对象拥有对唯一资源的拥有引用(项目中只能有一个实例), ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。